mirror of
https://github.com/inttter/md-badges.git
synced 2026-05-06 18:36:58 +02:00
feat: ✨ generate ref-style table - first cut
This commit is contained in:
parent
dd91b6dbad
commit
8498f2f736
5 changed files with 144 additions and 0 deletions
1
.github/scripts/extract-refstyle-badges/.gitignore
vendored
Normal file
1
.github/scripts/extract-refstyle-badges/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
md-badges.md
|
||||
76
.github/scripts/extract-refstyle-badges/extract-refstyle-badges.awk
vendored
Normal file
76
.github/scripts/extract-refstyle-badges/extract-refstyle-badges.awk
vendored
Normal file
|
|
@ -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<count; i++) {
|
||||
print "| "refsArray[i]" | `"refsArray[i]"` | `"defsArray[i]"`|" ;
|
||||
}
|
||||
|
||||
# blank line to end the (visible) table and start the (non-visible) reference definitions
|
||||
print;
|
||||
|
||||
# output the references
|
||||
for(j=0; j<count; j++) {
|
||||
print defsArray[j];
|
||||
}
|
||||
print;
|
||||
}
|
||||
44
.github/scripts/extract-refstyle-badges/extract-refstyle-badges.sh
vendored
Executable file
44
.github/scripts/extract-refstyle-badges/extract-refstyle-badges.sh
vendored
Executable file
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# #################################################################################
|
||||
# extract-refstyle-badges.sh
|
||||
#
|
||||
# Description:
|
||||
# Creates a table of reference-style markdown badges from the table rows in README.md
|
||||
#
|
||||
# #################################################################################
|
||||
|
||||
# get a reference to the current directory
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/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}"
|
||||
14
.github/workflows/extract-refstyle-badges.yml
vendored
Normal file
14
.github/workflows/extract-refstyle-badges.yml
vendored
Normal file
|
|
@ -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
|
||||
|
|
@ -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 <kbd>Ctrl</kbd> + <kbd>F</kbd> 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.
|
||||
|
||||
<!-- ### BEGIN GENERATED CONTENT -->
|
||||
<!-- any content between the above and below lines will be overwritten by the github action script -->
|
||||
<!-- ### END GENERATED CONTENT -->
|
||||
|
||||
## 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!
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue