nerd-fonts/bin/scripts/generate-css.sh
Fini Jastrow 41e0b16a4d generate-css: Do not rely on external minimalizer
[why]
The generated file `nerd-fonts-generated.css` is made smaller with an
external service as manual step...

  # [Nerd Fonts]  The following is generated from the build script, then through https://www.minifier.org/

We do not want any manual steps.

[how]
Luckily the difference is just to remove whitespaces and unneeded
semicoli. We can do the same while generating.

[note]
At first I tried to postprocess the generated file with sed, but of
course the strings that have blanks in them made that rather
complicated.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2022-09-11 16:41:12 +02:00

92 lines
2.4 KiB
Bash
Executable file

#!/usr/bin/env bash
# Nerd Fonts Version: 2.2.2
# Script Version: 1.1.1
# Generates CSS file for the font
# shellcheck disable=SC1091
source ./lib/i_all.sh
output_css_file="../../css/nerd-fonts-generated.css"
output_css_min_file="../../css/nerd-fonts-generated.min.css"
header_css_file="./css-header.txt"
header_css_min_file="./css-min-header.txt"
if [ -d "../../temp" ]; then
output_cheat_sheet_file="../../temp/nerd-fonts-generated-cheat-sheet.txt"
text_gen=" and Cheat Sheet HTML"
else
output_cheat_sheet_file="/dev/null"
fi
LINE_PREFIX="# [Nerd Fonts] "
version="2.2.2"
# clear files
true > "$output_css_file" 2> /dev/null
true > "$output_css_min_file" 2> /dev/null
true > "$output_cheat_sheet_file" 2> /dev/null
# describe how the classes were established
{
printf "/*\\n"
printf " *%s Website: https://www.nerdfonts.com\\n" "$LINE_PREFIX"
printf " *%s Development Website: https://github.com/ryanoasis/nerd-fonts\\n" "$LINE_PREFIX"
printf " *%s Version: %s\\n" "$LINE_PREFIX" "$version"
printf " *%s The following is generated from the build script\\n" "$LINE_PREFIX"
printf " */\\n"
} | tee "$output_css_min_file" >> "$output_css_file"
# add top section of CSS
{
printf "\\n"
cat "$header_css_file"
} >> "$output_css_file"
cat "$header_css_min_file" | tr -d '\n' >> "$output_css_min_file"
echo;
# shellcheck disable=SC2154
# we know the '$i' is from the sourced file
for var in "${!i@}"; do
# trim 'i_' prefix
glyph_name=${var#*_}
# 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'"
# generate css rules
{
printf ".nf-%s:before {" "$glyph_name"
printf "\\n"
printf " content: \"\\%s\";" "$glyph_code"
printf "\\n"
printf "}"
printf "\\n"
} >> "$output_css_file"
# generate css min rules
{
printf ".nf-%s:before{content:\"\\%s\"}" "$glyph_name" "$glyph_code"
} >> "$output_css_min_file"
# generate HTML cheat sheet
{
printf "<div class=\"column\">"
printf "\\n"
printf " <div class=\"nf nf-%s center\"></div>" "$glyph_name"
printf "\\n"
printf " <span><div class=\"class-name\">nf-%s</div><div class=\"codepoint\">%s</div></span>" "$glyph_name" "$glyph_code"
printf "\\n"
printf "</div>"
printf "\\n"
} >> "$output_cheat_sheet_file"
done
printf "Generated CSS${text_gen}\\n"