webfonts

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 4 Imported by: 0

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

View Source
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

View Source
var Providers = []string{"google", "bunny"}

Providers are the accepted values of theme.web_fonts.

Functions

func Families

func Families(tokenMaps ...map[string]string) []string

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(provider string, families []string) string

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

func IsGeneric(name string) bool

IsGeneric reports whether name is a CSS generic family or a system font keyword such as system-ui or -apple-system.

func Lookup

func Lookup(name string) (canonical, category string, ok bool)

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

func PrimaryFamily(stack string) string

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 StackHas added in v1.5.1

func StackHas(stack, family string) bool

StackHas reports whether a CSS font stack names family, compared whole and case-insensitively: `'Inter Tight', sans-serif` does not have "Inter".

func StylesheetURL

func StylesheetURL(provider string, families []string) string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL