Classes
AssetURLMixin
Mixin providing asset URL generation for TemplateEngine.
Requires these attributes on the host cla…
AssetURLMixin
Mixin providing asset URL generation for TemplateEngine.
Requires these attributes on the host class:
- site: Site instance
- _asset_manifest_path: Path
Requires these methods from ManifestHelpersMixin (must come BEFORE this mixin in MRO):
- _get_manifest_entry(logical_path: str) -> AssetManifestEntry | None
- _warn_manifest_fallback(logical_path: str) -> None
Attributes
| Name | Type | Description |
|---|---|---|
site |
Any |
|
_asset_manifest_path |
Path |
Internal Methods 3
_asset_url
Generate URL for an asset.
Handles:
- Manifest lookup for fingerprinted assets…
_asset_url
def _asset_url(self, asset_path: str, page_context: Any = None) -> str
Generate URL for an asset.
Handles:
- Manifest lookup for fingerprinted assets
- file:// protocol with relative paths
- Dev server mode (no fingerprints)
- Fallback to direct asset paths
Parameters 2
asset_path |
str |
Path to asset file |
page_context |
Any |
Optional page context for computing relative paths |
Returns
Asset URLstr
—
_asset_url_file_protocol
Generate asset URL for file:// protocol using relative paths.
_asset_url_file_protocol
def _asset_url_file_protocol(self, safe_asset_path: str, page_context: Any) -> str
Generate asset URL for file:// protocol using relative paths.
Parameters 2
safe_asset_path |
str |
Validated asset path |
page_context |
Any |
Page context for computing relative path |
Returns
Relative asset URLstr
—
_find_fingerprinted_asset
Find fingerprinted version of asset in output directory.
_find_fingerprinted_asset
def _find_fingerprinted_asset(self, safe_asset_path: str) -> str | None
Find fingerprinted version of asset in output directory.
Parameters 1
safe_asset_path |
str |
Validated asset path |
Returns
Fingerprinted asset path if found, None otherwisestr | None
—
Functions
normalize_and_validate_asset_path
Normalize and validate the provided asset path to prevent traversal/absolute paths.
normalize_and_validate_asset_path
def normalize_and_validate_asset_path(raw_path: str) -> str
Normalize and validate the provided asset path to prevent traversal/absolute paths.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
raw_path |
str |
— | Raw asset path from template |
Returns
Sanitized asset path, or empty string if invalidstr
—
compute_relative_asset_path
Compute relative path from page to asset for file:// protocol.
compute_relative_asset_path
def compute_relative_asset_path(asset_path: str, page_context: Any, output_dir: Path) -> str | None
Compute relative path from page to asset for file:// protocol.
Parameters 3
| Name | Type | Default | Description |
|---|---|---|---|
asset_path |
str |
— | Asset path (e.g., 'assets/css/style.css') |
page_context |
Any |
— | Page context with output_path |
output_dir |
Path |
— | Site output directory |
Returns
Relative path string, or None if cannot computestr | None
—