Classes
CascadeEngine
Isolated cascade application logic with pre-computed O(1) lookups.
Handles metadata cascading wher…
CascadeEngine
Isolated cascade application logic with pre-computed O(1) lookups.
Handles metadata cascading where section _index.md files can define cascade metadata that propagates to descendant pages. This allows setting common metadata at the section level rather than repeating it on every page.
Pre-computes page-section relationships to avoid O(n²) lookups when determining if a page is top-level (not in any section).
Attributes
| Name | Type | Description |
|---|---|---|
pages |
— | All pages in the site |
sections |
— | All sections in the site |
_pages_in_sections |
— | Pre-computed set of pages that belong to sections (O(1) lookup) |
Methods 2
is_top_level_page
Check if a page is top-level (not in any section).
O(1) lookup using pre-compu…
is_top_level_page
def is_top_level_page(self, page: Any) -> bool
Check if a page is top-level (not in any section).
O(1) lookup using pre-computed set.
Parameters 1
page |
Any |
Page object to check |
Returns
True if page is not in any section, False otherwisebool
—
apply
Apply cascade metadata from sections to pages.
Processes root-level cascades f…
apply
def apply(self) -> dict[str, Any]
Apply cascade metadata from sections to pages.
Processes root-level cascades first, then recursively applies cascades through the section hierarchy. Returns statistics about what was cascaded.
Returns
Dictionary with cascade statistics:dict[str, Any]
—
Internal Methods 3
__init__
Initialize cascade engine with site pages and sections.
__init__
def __init__(self, pages: list[Any], sections: list[Any]) -> None
Initialize cascade engine with site pages and sections.
Parameters 2
pages |
list[Any] |
List of all Page objects in the site |
sections |
list[Any] |
List of all Section objects in the site |
_compute_pages_in_sections
Pre-compute set of all pages that belong to any section.
This enables O(1) loo…
_compute_pages_in_sections
def _compute_pages_in_sections(self, sections: list[Any]) -> set[Any]
Pre-compute set of all pages that belong to any section.
This enables O(1) lookup later instead of searching all sections for each page. Called once during initialization.
Parameters 1
sections |
list[Any] |
List of Section objects |
Returns
Set of Page objects that belong to at least one sectionset[Any]
—
_apply_section_cascade
Recursively apply cascade metadata to a section and its descendants.
Cascade m…
_apply_section_cascade
def _apply_section_cascade(self, section: Any, parent_cascade: dict[str, Any] | None = None, stats: dict[str, Any] | None = None) -> None
Recursively apply cascade metadata to a section and its descendants.
Cascade metadata accumulates through the hierarchy - child sections inherit from parent and can override/extend it.
Parameters 3
section |
Any |
Section to apply cascade to |
parent_cascade |
dict[str, Any] | None |
Cascade metadata inherited from parent sections |
stats |
dict[str, Any] | None |
Statistics dictionary to update (for tracking what was cascaded) |