nerd-fonts/bin/scripts/generate-css.sh

76 lines
1.9 KiB
Bash
Raw Normal View History

#!/bin/bash
2018-03-03 20:14:22 +01:00
# Nerd Fonts Version: 2.0.0
# Script Version: 1.0.0
# Generates CSS file for the font
2018-01-13 04:20:52 +01:00
# shellcheck disable=SC1091
source ./lib/i_all.sh
output_css_file="../../css/nerd-fonts-generated.css"
header_css_file="./css-header.txt"
output_cheat_sheet_file="../../temp/nerd-fonts-generated-cheat-sheet.txt"
2017-05-19 10:14:53 +02:00
LINE_PREFIX="# [Nerd Fonts] "
version="2.0.0"
# clear files
2018-01-13 04:20:52 +01:00
true > "$output_css_file" 2> /dev/null
true > "$output_cheat_sheet_file" 2> /dev/null
# describe how the classes were established
{
2018-01-13 04:20:52 +01:00
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\\n"
# add top section of CSS
cat $header_css_file
} >> "$output_css_file"
echo;
2018-01-12 03:47:59 +01:00
# 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, .nerd-font-%s:before, .nerd-fonts-%s:before {" "$glyph_name" "$glyph_name" "$glyph_name"
2018-01-13 04:20:52 +01:00
printf "\\n"
printf " content: \"\\%s\";" "$glyph_code"
printf "\\n"
printf "}"
2018-01-13 04:20:52 +01:00
printf "\\n"
} >> "$output_css_file"
# generate HTML cheat sheet
{
printf "<div class=\"column\">"
2018-01-13 04:20:52 +01:00
printf "\\n"
printf " <div class=\"nerd-font nerd-font-%s center\"></div>" "$glyph_name"
2018-01-13 04:20:52 +01:00
printf "\\n"
printf " <span>nf-%s <br/>(%s)</span>" "$glyph_name" "$glyph_code"
2018-01-13 04:20:52 +01:00
printf "\\n"
printf "</div>"
2018-01-13 04:20:52 +01:00
printf "\\n"
} >> "$output_cheat_sheet_file"
done
2018-01-13 04:20:52 +01:00
printf "Generated CSS and Cheat Sheet HTML\\n"