Functions
_get_icons_directory
Get the icons directory from the default theme.
_get_icons_directory
def _get_icons_directory() -> Path
Get the icons directory from the default theme.
Returns
Path
_preload_all_icons
Pre-load all icons into memory at startup.
Called once during template engine initialization. Load…
_preload_all_icons
def _preload_all_icons() -> None
Pre-load all icons into memory at startup.
Called once during template engine initialization. Loads all SVG files from the icons directory into the _preloaded_icons cache.
_escape_attr
Escape HTML attribute value.
_escape_attr
def _escape_attr(value: str) -> str
Escape HTML attribute value.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
value |
str |
— |
Returns
str
_render_icon_cached
Render an icon with LRU caching for repeated calls.
The cache key is (name, size, css_class, aria_…
_render_icon_cached
def _render_icon_cached(name: str, size: int, css_class: str, aria_label: str) -> str
Render an icon with LRU caching for repeated calls.
The cache key is (name, size, css_class, aria_label). This captures the vast majority of repeated icon renders (e.g., navigation icons appear on every page with the same parameters).
Parameters 4
| Name | Type | Default | Description |
|---|---|---|---|
name |
str |
— | Icon name (already mapped through ICON_MAP) |
size |
int |
— | Icon size in pixels |
css_class |
str |
— | Additional CSS classes |
aria_label |
str |
— | Accessibility label |
Returns
Rendered SVG HTML string, or empty string if icon not foundstr
—
icon
Render an SVG icon for use in templates.
Uses pre-loaded icons and LRU caching for optimal perform…
icon
def icon(name: str, size: int = 24, css_class: str = '', aria_label: str = '') -> Markup
Render an SVG icon for use in templates.
Uses pre-loaded icons and LRU caching for optimal performance. Icons are loaded once at startup and rendered output is cached by (name, size, css_class, aria_label) to minimize repeated work.
Icon name mapping priority:
- theme.yaml aliases (if theme config available)
- ICON_MAP (fallback for backwards compatibility)
Parameters 4
| Name | Type | Default | Description |
|---|---|---|---|
name |
str |
— | Icon name (e.g., "search", "menu", "close", "arrow-up") |
size |
int |
24 |
Icon size in pixels (default: 24) |
css_class |
str |
'' |
Additional CSS classes |
aria_label |
str |
'' |
Accessibility label (if empty, uses aria-hidden) |
Returns
Markup object containing inline SVG HTML, or empty Markup if icon not foundMarkup
—
register
Register icon template functions and pre-load all icons.
Pre-loads all SVG icons into memory at re…
register
def register(env: Environment, site: Site) -> None
Register icon template functions and pre-load all icons.
Pre-loads all SVG icons into memory at registration time for optimal render performance. Icons are typically ~50KB total.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
env |
Environment |
— | Jinja2 environment |
site |
Site |
— | Site instance (stored for theme config access) |
get_icon_cache_stats
Get icon cache statistics for debugging/profiling.
get_icon_cache_stats
def get_icon_cache_stats() -> dict[str, int]
Get icon cache statistics for debugging/profiling.
Returns
Dictionary with cache hit/miss informationdict[str, int]
—
clear_icon_cache
Clear the icon render cache.
Useful for testing or when icons are modified during development.
clear_icon_cache
def clear_icon_cache() -> None
Clear the icon render cache.
Useful for testing or when icons are modified during development.