Classes
FontHelper
Main font helper interface.
Usage:
helper = FontHelper(config)
helper.process(output_dir)
FontHelper
Main font helper interface.
Usage:
helper = FontHelper(config)
helper.process(output_dir)
Methods 1
process
Process fonts: download files and generate CSS.
process
def process(self, assets_dir: Path) -> Path | None
Process fonts: download files and generate CSS.
Parameters 1
assets_dir |
Path |
Assets directory (fonts go in assets/fonts/) |
Returns
Path to generated fonts.css, or None if no fonts configuredPath | None
—
Internal Methods 2
__init__
Initialize font helper with configuration.
__init__
def __init__(self, font_config: dict[str, Any])
Initialize font helper with configuration.
Parameters 1
font_config |
dict[str, Any] |
[fonts] section from bengal.toml |
_parse_config
Parse [fonts] configuration into normalized format.
Supports two formats:
1. S…
_parse_config
def _parse_config(self) -> dict[str, dict[str, Any]]
Parse [fonts] configuration into normalized format.
Supports two formats:
- Simple string: "Inter:400,600,700"
- Detailed dict: {family = "Inter", weights = [400, 600, 700]}
Returns
Dict mapping font name to font specificationdict[str, dict[str, Any]]
—
Functions
rewrite_font_urls_with_fingerprints
Rewrite font URLs in fonts.css to use fingerprinted filenames.
After asset fingerprinting, font fi…
rewrite_font_urls_with_fingerprints
def rewrite_font_urls_with_fingerprints(fonts_css_path: Path, asset_manifest: dict[str, Any]) -> bool
Rewrite font URLs in fonts.css to use fingerprinted filenames.
After asset fingerprinting, font files have hashed names like: fonts/outfit-400.6c18d579.woff2
This function updates fonts.css to reference these fingerprinted names instead of the original names like fonts/outfit-400.woff2.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
fonts_css_path |
Path |
— | Path to fonts.css in output directory |
asset_manifest |
dict[str, Any] |
— | Asset manifest dict with 'assets' key mapping logical paths to fingerprinted output paths |
Returns
True if fonts.css was updated, False otherwisebool
—