github.com/elves/elvish@v0.15.0/website/gen-fonts-css.elv (about)

     1  # Generates fonts.css by doing the following:
     2  #
     3  # 1. Download Source Serif Pro and Fira Mono
     4  #
     5  # 2. Downsize them by only keeping the Latin glyphs
     6  #
     7  # 3. Embed into the CSS file as base64
     8  #
     9  # External dependencies:
    10  #   base64: for encoding to base64
    11  #   curl: for downloading files
    12  #   fonttools: for processing font files
    13  
    14  # Subset of glyphs to include, other than ASCII. Discovered with:
    15  #
    16  # cat **.html | go run ./cmd/runefreq | sort -nr
    17  subset=…’“”
    18  
    19  mkdir -p _fonts_tmp
    20  pwd=_fonts_tmp {
    21    @ssp-files-base = SourceSerifPro-{Regular It Semibold SemiboldIt}
    22    for base $ssp-files-base {
    23      curl -C - -L -o $base.otf -s https://github.com/adobe-fonts/source-serif-pro/raw/release/OTF/$base.otf
    24    }
    25    @fm-files-base = FiraMono-{Regular Bold}
    26    for base $fm-files-base {
    27      curl -C - -L -o $base.otf -s https://github.com/mozilla/Fira/raw/master/otf/$base.otf
    28    }
    29    for base [$@ssp-files-base $@fm-files-base] {
    30      fonttools subset $base.otf --unicodes=00-7f --text=$subset
    31      fonttools ttLib.woff2 compress -o $base.subset.woff2 $base.subset.otf
    32    }
    33  }
    34  
    35  fn font-face [family weight style file]{
    36    echo "@font-face {
    37      font-family: "$family";
    38      font-weight: "$weight";
    39      font-style: "$style";
    40      font-strecth: normal;
    41      src: url('data:font/woff2;charset=utf-8;base64,"(base64 -w0 _fonts_tmp/$file.subset.woff2 | slurp)"') format('woff2');
    42  }"
    43  }
    44  
    45  font-face 'Source Serif Pro' 400 normal SourceSerifPro-Regular
    46  font-face 'Source Serif Pro' 400 italic SourceSerifPro-It
    47  font-face 'Source Serif Pro' 600 normal SourceSerifPro-Semibold
    48  font-face 'Source Serif Pro' 600 italic SourceSerifPro-SemiboldIt
    49  
    50  font-face 'Fira Mono' 400 normal FiraMono-Regular
    51  font-face 'Fira Mono' 600 normal FiraMono-Bold