Google Fonts
Import a Google Fonts stylesheet from CSS. The build downloads the font files and serves them from the site, so pages make no request to Google:
@import url("https://fonts.googleapis.com/css2?family=Figtree:wght@400;700&display=swap");
:global(body) {
font-family: "Figtree", "Figtree Fallback", system-ui, sans-serif;
}
Put the import in the stylesheet of the outermost layout, so every page gets it.
The fallback family
"Figtree Fallback" is a generated local font with metrics that match
Figtree. Name it after the web font, and text does not move when the web font
loads.
The cache
Downloaded fonts are kept in ~/.cache/rista/fonts, or under
$XDG_CACHE_HOME when that is set. build and serve need the network
only the first time a font is used, and work offline after that.
- A font file is kept for good, because it never changes at its URL.
- A stylesheet is fetched again after a week. When that fails, the old one is used.
| To | Do |
|---|---|
| Move the cache | set RISTA_FONT_CACHE to a directory |
| Download every time | set RISTA_FONT_CACHE=off |
| Set it for one site | plugins Rista.plugins(font_cache: "tmp/fonts") in klenod.config.rb |
| Get new font files now | delete the directory |
What is written
Each family becomes a stylesheet and its font files, all under /assets/ with
a content hash. This site links three:
/assets/google_fonts_afacad.<hash>.css
/assets/google_fonts_domine.<hash>.css
/assets/google_fonts_jetbrains_mono.<hash>.css