nerd-fonts/bin/scripts/generate-css.sh
Fini Jastrow 83b3d02d41 generate-css: Add codepoint to glyphnames.json
[why]
Just having the characters themselves as data for the name is convenient
in some cases; but sometimes the codepoint is also nice. And it
certainly improves the human interaction / check of the file.

[how]
Include the character and the codepoint in the glyph-name data. This is
a breaking change. But given that the json file is rather new I believe
we can get away with it.

Sorry for the inconvenience for all the early adaptors that already use
the old/previous format. But now we are more future proof and can add
even more data without breaking old json code.

Related:
https://github.com/ryanoasis/nerd-fonts/issues/1140
https://github.com/kovidgoyal/kitty/issues/2972
https://github.com/chrisbra/unicode.vim/issues/39
https://github.com/ryanoasis/nerd-fonts/issues/448
https://github.com/nvim-tree/nvim-web-devicons/issues/192

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-03-12 21:17:08 +01:00

119 lines
3.4 KiB
Bash
Executable file

#!/usr/bin/env bash
# Nerd Fonts Version: 2.3.3
# Script Version: 1.2.0
# Generates CSS file for the font and cheat sheet code
# 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="./data/css-header.txt"
header_css_min_file="./data/css-min-header.txt"
output_json_file="../../glyphnames.json"
if [ ! -d "../../temp" ]; then
mkdir "../../temp"
fi
output_cheat_sheet_file="../../temp/2017-01-04-icon-cheat-sheet.md"
cheat_sheet_head_file="./data/cheatsheet-head.txt"
cheat_sheet_foot_file="./data/cheatsheet-foot.txt"
LINE_PREFIX="# [Nerd Fonts] "
version="2.3.3"
# 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
true > "$output_json_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"
cat "$cheat_sheet_head_file" > "$output_cheat_sheet_file"
# add top section of json
{
printf "{\"METADATA\":{"
printf "\"website\":\"https://www.nerdfonts.com\","
printf "\"development-website\":\"https://github.com/ryanoasis/nerd-fonts\","
printf "\"version\":\"$version\","
printf "\"date\":\"$(date -u --rfc-3339=seconds)\""
printf "}"
} >> "$output_json_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"
if [[ "$glyph_name" = mdi-* ]]; then
printf " <span class=\"corner-red\"></span><span class=\"corner-text\">obsolete</span>\\n"
fi
printf " <div class=\"nf nf-%s center\"></div>" "$glyph_name"
printf "\\n"
printf " <div class=\"class-name\">nf-%s</div><div title=\"Copy Hex Code to Clipboard\" class=\"codepoint\">%s</div>" "$glyph_name" "$glyph_code"
printf "\\n"
printf " </div>"
printf "\\n"
} >> "$output_cheat_sheet_file"
# generate json entry
{
printf ",\"%s\":{\"char\":\"%s\",\"code\":\"%s\"}" "$glyph_name" "$glyph_char" "$glyph_code"
} >> "$output_json_file"
done
cat "$cheat_sheet_foot_file" >> "$output_cheat_sheet_file"
printf "}\n" >> "$output_json_file"
printf "Generated CSS, json, and Cheat Sheet HTML\\n"