From 6e1414fe464d0f97b7c63e64719512f28616215c Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Tue, 26 Nov 2024 12:20:07 +0100 Subject: [PATCH 1/2] generate-css: Speedup by factor of 25 [why] The script is extremely slow. [how] Instead of spawning a new subshell for each glyph (to determine the codepoint of a char), execute the printf within the current shell. Before: ./generate-css.sh 25,06s user 33,26s system 101% cpu 57,414 total After: ./generate-css.sh 1,89s user 0,50s system 102% cpu 2,330 total Signed-off-by: Fini Jastrow --- bin/scripts/generate-css.sh | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/bin/scripts/generate-css.sh b/bin/scripts/generate-css.sh index 805aa137ae..c5fac7c0c5 100755 --- a/bin/scripts/generate-css.sh +++ b/bin/scripts/generate-css.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # Nerd Fonts Version: 3.3.0 -# Script Version: 1.2.1 +# Script Version: 1.3.0 # Generates CSS file for the font and cheat sheet code # shellcheck disable=SC1091 # Do not pull in the sourced file @@ -70,13 +70,11 @@ for var in "${!i@}"; do # replace _ with - glyph_name=${glyph_name/_/-} glyph_char=${!var} - glyph_code=$(printf "%x" "'$glyph_char'") #echo "$var=${!var}" #echo "$glyph_name" #echo "$glyph_char" - #echo "$glyph_code" #printf "%x" "'$glyph_char'" if [[ "$glyph_name" != mdi-* ]]; then @@ -84,7 +82,7 @@ for var in "${!i@}"; do { printf ".nf-%s:before {" "$glyph_name" printf "\\n" - printf " content: \"\\%s\";" "$glyph_code" + printf " content: \"\\%x\";" "'$glyph_char'" printf "\\n" printf "}" printf "\\n" @@ -92,18 +90,18 @@ for var in "${!i@}"; do # generate css min rules { - printf ".nf-%s:before{content:\"\\%s\"}" "$glyph_name" "$glyph_code" + printf ".nf-%s:before{content:\"\\%x\"}" "$glyph_name" "'$glyph_char'" } >> "$output_css_min_file" # generate json entry { - printf ",\"%s\":{\"char\":\"%s\",\"code\":\"%s\"}" "$glyph_name" "$glyph_char" "$glyph_code" + printf ",\"%s\":{\"char\":\"%s\",\"code\":\"%x\"}" "$glyph_name" "$glyph_char" "'$glyph_char'" } >> "$output_json_file" else # generate css min rules for removed glyphs { - printf ".nfold-%s:before{content:\"\\%s\"}" "$glyph_name" "$glyph_code" + printf ".nfold-%s:before{content:\"\\%x\"}" "$glyph_name" "'$glyph_char'" } >> "$output_css_min_rem_file" fi @@ -114,7 +112,7 @@ for var in "${!i@}"; do else namespace="nf" fi - printf " \"%s-%s\": \"%s\",\\n" "$namespace" "$glyph_name" "$glyph_code" + printf " \"%s-%s\": \"%x\",\\n" "$namespace" "$glyph_name" "'$glyph_char'" } >> "$output_cheat_sheet_file" done From 34620c52cc1235ea71d8549a8ead50a33cd084e9 Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Tue, 26 Nov 2024 14:12:15 +0100 Subject: [PATCH 2/2] CI: Regenerate glyphnames before release [why] When the icon sets have changed (added or names changed) the i_*.sh files are (hopefully) up to date, but the glyphnames.json file is only updated on release. Unfortunately the font-patcher uses the glyphnames.json to determine the patched-in glyphs' names, but in the workflow the json file is only updated after all fonts have been patched. [how] Like the version number in the font-patcher file we also create a transient glyphnames.json in each patching job, that the font-patcher can then utilize. Still the in-repo glyphnames.json is only updated after successful release. So in pinciple we call the generate-css.sh (which also generates the glyphnames.json) once for every font in the font matrix (just before patching) and then finally after all patching has been done again and that is committed back to the repo. Fixes: #1745 Signed-off-by: Fini Jastrow --- .github/workflows/release.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cbdedc5ea8..5a7fe4ad84 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -198,10 +198,13 @@ jobs: fontforge --version fontforge --version 2>&1 | grep libfontforge | awk '{print $NF}' - - name: Bump version for source files + - name: Bump version for source files and update glyphnames.json + # and check if generated glyphnames.json is valid run: | cd -- "$GITHUB_WORKSPACE/bin/scripts" ./version-bump.sh "$RELEASE_VERSION" + ./generate-css.sh + jq . ../../glyphnames.json > /dev/null - name: Patch all the variations of the font family run: |