diff --git a/.github/scripts/extract-refstyle-badges/.gitignore b/.github/scripts/extract-refstyle-badges/.gitignore new file mode 100644 index 0000000..8fc28cc --- /dev/null +++ b/.github/scripts/extract-refstyle-badges/.gitignore @@ -0,0 +1 @@ +md-badges.md diff --git a/.github/scripts/extract-refstyle-badges/extract-refstyle-badges.awk b/.github/scripts/extract-refstyle-badges/extract-refstyle-badges.awk new file mode 100644 index 0000000..07667e9 --- /dev/null +++ b/.github/scripts/extract-refstyle-badges/extract-refstyle-badges.awk @@ -0,0 +1,76 @@ +BEGIN{ + # initialize vars + TRUE=1; + FALSE=0; + count=0; + shouldSkip=FALSE; + # 'delete' initializes a var as an array + delete labelsArray[0]; + delete defsArray[0]; + delete refsArray[0]; + # printf "" > "errors.txt"; +} +/^| \[/{ + # initialize our variables + shouldSkip=FALSE; + label=$2; + url=$2; + # extract the label by removing everything before and after it + gsub(/^[[:space:]]*\[!\[/, "", label); + gsub(/\].*$/, "", label); + + # extract the URL by removing everything before and after it + gsub(/^[^\(]*\(/,"",url); + gsub(/\)\].*$/,"",url); + + if (label == "") { + # print "label is empty: '"label"'; url='"url"'\n" >> "errors.txt" ; + + shouldSkip=TRUE; + } + + # ensure our label is unique by appending _alt to it + if (shouldSkip == FALSE) { + while(label in labelsRecordArray && shouldSkip == FALSE) { + # print "Found duplicate label: '"label"'; labelsRecordArray[label]=='"labelsRecordArray[label]"'; url='"url"'\n" >> "errors.txt" ; + if (labelsRecordArray[label] == url) { + shouldSkip=TRUE; + } else { + label=label"_alt" ; + } + } + } + + if (shouldSkip == FALSE) { + # append this label to the set of unique labels + labelsRecordArray[label] = url; + + # generate the markdown code for this label and url + refcode = "!["label"]["label"]"; + defcode = "["label"]: "url" \""label"\""; + + # store our markdown code against the label + labelsArray[count] = label; + defsArray[count] = defcode; + refsArray[count] = refcode; + count++; + } +} +END{ + # output the markdown table + print "| Preview | Reference Markdown Code | Definition Markdown Code |" + print "|---------|------------------------|------------------------|" + + for(i=0; i/dev/null 2>&1 && pwd )" +READMEFILE="${DIR}/../../../README.md" + +# extract the table rows from README.md, sort them, and pass them to +# the awk script to generate the reference-style link for each row. +# Add a newline at the end and write to md-badges.md +readmerows=$( + cat "${READMEFILE}" | \ + grep -E '^\| \[' | \ + sort +) + +# add a newline before processing with awk +printf "%s\n" "$readmerows" \ + | awk -F '|' -f "${DIR}/extract-refstyle-badges.awk" \ +> md-badges.md + +# now insert the generated md-badges.md content into README.md + +lead='^<\!-- ### BEGIN GENERATED CONTENT -->' +tail='^<\!-- ### END GENERATED CONTENT -->' + +sed -e "/$lead/,/$tail/{ + /$lead/{ + p; + r md-badges.md + }; + /$tail/p; + d +}" "${READMEFILE}" > "${READMEFILE}.tmp" +mv "${READMEFILE}.tmp" "${READMEFILE}" + +# echo "${READMEFILE}" \ No newline at end of file diff --git a/.github/workflows/extract-refstyle-badges.yml b/.github/workflows/extract-refstyle-badges.yml new file mode 100644 index 0000000..efd4779 --- /dev/null +++ b/.github/workflows/extract-refstyle-badges.yml @@ -0,0 +1,14 @@ +name: Extract refstyle badges + +on: + push: + branches: + - main + - feature/reference-style-table +jobs: + extract-refstyle-badges: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: extract refstyle badges + run: ${{github.workspace}}/.github/scripts/extract-refstyle-badges/extract-refstyle-badges.sh diff --git a/README.md b/README.md index a1b5591..cce9fad 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ An extensive list of static Shields.io badges, sorted by category. * [Version Control](#-version-control) * [Virtual Reality](#%EF%B8%8F-virtual-reality) * [Website Status](#-website-status) +* [Reference-Style Badges](#reference-style-badges) > **Tip:** Use Ctrl + F to quickly search for and find a badge. @@ -974,6 +975,14 @@ An extensive list of static Shields.io badges, sorted by category. --- +## Reference-Style Badges + +The table below is automatically created. It contains the above badges, in a reference-style format. + + + + + ## CLI If you want to find badges from directly within your terminal, check out [mdbadges-cli](https://github.com/inttter/mdbadges-cli), which includes all the badges listed under this repository, and also offers various commands, like creating custom badges!