Documentation
¶
Overview ¶
Package webfonts decides which of a site's theme fonts to load from a web font service (theme.web_fonts) and builds the <head> links for them.
Both services take the Google Fonts CSS v1 syntax (`/css?family=A:400,700|B:400&display=swap`). That form skips the weights and styles a family lacks instead of failing the request, so the engine asks every family for the theme's full weight set and needs no per-family weight data: only the family names in families.tsv (generated by tools/webfonts-catalog). Browsers download only the faces a page uses.
Index ¶
- Constants
- Variables
- func Families(tokenMaps ...map[string]string) []string
- func HeadLinks(provider string, families []string) string
- func IsGeneric(name string) bool
- func Lookup(name string) (canonical, category string, ok bool)
- func PrimaryFamily(stack string) string
- func StylesheetURL(provider string, families []string) string
Constants ¶
const Weights = "400,400i,500,600,700,700i,800"
Weights requested for every family: the weights the default theme uses (400 to 800) and the italics Markdown emphasis needs.
Variables ¶
var Providers = []string{"google", "bunny"}
Providers are the accepted values of theme.web_fonts.
Functions ¶
func Families ¶
Families returns the canonical names of the catalog families the given token maps (resolved light and dark tokens) use as their primary font, without the bundled fonts, deduplicated and in a stable order.
func HeadLinks ¶
HeadLinks is the <head> markup for the families: preconnects to the provider's hosts, then the stylesheet. It returns "" when there is nothing to load.
func IsGeneric ¶
IsGeneric reports whether name is a CSS generic family or a system font keyword such as system-ui or -apple-system.
func Lookup ¶
Lookup finds a family in the catalog, ignoring case. It returns the family's canonical name (the services match names case-sensitively) and its category: sans-serif, serif, display, handwriting or monospace.
func PrimaryFamily ¶
PrimaryFamily returns the first named family in a CSS font stack, without its quotes, skipping generic keywords: `'Merriweather', Georgia, serif` gives "Merriweather" and `system-ui, sans-serif` gives "".
func StylesheetURL ¶
StylesheetURL is the one stylesheet URL that loads all the families from the provider, or "" for an unknown provider or no families. The families travel in a single `family=` parameter joined with `|`: Bunny's CDN keys its cache on the first `family=` only, so repeating the parameter can serve another site's fonts.
Types ¶
This section is empty.