Classes
CSSOptimizer
11
▼
Generates optimized CSS bundles based on site content.
**Analyzes pages and sections to detect:**
…
CSSOptimizer
11
▼
Generates optimized CSS bundles based on site content.
Analyzes pages and sections to detect:
- Content types in use (blog, doc, tutorial, etc.)
- Features enabled (graph, search, mermaid, etc.)
Then generates a minimal style.css containing only needed imports.
Attributes
| Name | Type | Description |
|---|---|---|
site |
— |
Site instance to analyze |
_manifest |
CSSManifest
|
Loaded CSS manifest from theme |
Methods
get_used_content_types
0
set[str]
▼
Scan site to find all content types in use.
**Checks:**
- page.metadata.type f…
get_used_content_types
0
set[str]
▼
def get_used_content_types(self) -> set[str]
Scan site to find all content types in use.
Checks:
- page.metadata.type for each page
- section.metadata.content_type for each section
Returns
set[str]
Set of content type names (e.g., {"blog", "doc"})
get_enabled_features
0
set[str]
▼
Detect features that require CSS.
**Checks:**
- site.features_detected (popula…
get_enabled_features
0
set[str]
▼
def get_enabled_features(self) -> set[str]
Detect features that require CSS.
Checks:
- site.features_detected (populated during discovery phase)
- site.config.features (explicit overrides)
Returns
set[str]
Set of feature names (e.g., {"search", "graph"})
get_required_css_files
0
list[str]
▼
Determine which CSS files are needed.
**Combines:**
- Core CSS (always)
- Pale…
get_required_css_files
0
list[str]
▼
def get_required_css_files(self) -> list[str]
Determine which CSS files are needed.
Combines:
- Core CSS (always)
- Palettes (all or just active based on config)
- Shared CSS (always)
- Type-specific CSS (based on content types)
- Feature-specific CSS (based on features)
- Force-include from config
Returns
list[str]
Ordered list of CSS file paths (relative to css/ directory)
generate
1
str | tuple[str, CSSOpti…
▼
Generate optimized style.css content.
Creates a CSS file with @layer imports c…
generate
1
str | tuple[str, CSSOpti…
▼
def generate(self, report: bool = False) -> str | tuple[str, CSSOptimizationReport]
Generate optimized style.css content.
Creates a CSS file with @layer imports containing only the CSS files needed for the detected content types and features.
Parameters
| Name | Type | Description |
|---|---|---|
report |
— |
If True, also return optimization report Default:False
|
Returns
str | tuple[str, CSSOptimizationReport]
CSS content string, or tuple of (css_content, report_dict) if report=True
Internal Methods 5 ▼
__init__
1
▼
Initialize CSS optimizer.
__init__
1
▼
def __init__(self, site: SiteLike) -> None
Parameters
| Name | Type | Description |
|---|---|---|
site |
— |
Site instance to analyze for content types and features |
_load_manifest
0
CSSManifest
▼
Load CSS manifest from theme.
Attempts to load the CSS manifest from the activ…
_load_manifest
0
CSSManifest
▼
def _load_manifest(self) -> CSSManifest
Load CSS manifest from theme.
Attempts to load the CSS manifest from the active theme. Falls back to empty manifest if theme doesn't have one.
Returns
CSSManifest
CSSManifest dictionary with categorized CSS files
_get_theme_dir
1
Any
▼
Get the directory path for a theme.
_get_theme_dir
1
Any
▼
def _get_theme_dir(self, theme_name: str) -> Any
Parameters
| Name | Type | Description |
|---|---|---|
theme_name |
— |
Returns
Any
_load_manifest_from_path
1
CSSManifest
▼
Load manifest from a Python file path.
_load_manifest_from_path
1
CSSManifest
▼
def _load_manifest_from_path(self, manifest_path: Any) -> CSSManifest
Parameters
| Name | Type | Description |
|---|---|---|
manifest_path |
— |
Returns
CSSManifest
_get_all_css_files
0
list[str]
▼
Get list of all CSS files in manifest.
_get_all_css_files
0
list[str]
▼
def _get_all_css_files(self) -> list[str]
Returns
list[str]
Functions
optimize_css_for_site
1
str
▼
Convenience function to generate optimized CSS.
optimize_css_for_site
1
str
▼
def optimize_css_for_site(site: SiteLike) -> str
Parameters
| Name | Type | Description |
|---|---|---|
site |
SiteLike |
Site instance |
Returns
str