Classes
PageCore
dataclass
Cacheable page metadata shared between Page, PageMetadata, and PageProxy.
This is the single sourc…
PageCore
dataclass Cacheable page metadata shared between Page, PageMetadata, and PageProxy.
This is the single source of truth for all cacheable page data. All fields here can be serialized to JSON and stored in .bengal/page_metadata.json for incremental builds.
CacheableAttributes
| Name | Type | Description |
|---|---|---|
source_path |
str |
Path to source markdown file (relative to content dir). Used as cache key and for file change detection. |
title |
str |
Page title from frontmatter or filename. Required field, defaults to "Untitled" if not provided. |
date |
datetime | None |
Publication date from frontmatter. Used for sorting, archives, and RSS feeds. None if not specified. |
tags |
list[str] |
List of tag strings from frontmatter. Used for taxonomy pages and filtering. Empty list if not specified. |
slug |
str | None |
URL slug for this page. Overrides default slug derived from filename. None means use default. |
weight |
int | None |
Sort weight within section. Lower numbers appear first. None means use default sorting. |
lang |
str | None |
Language code for i18n (e.g., "en", "es", "fr"). None means use site default language. |
type |
str | None |
Page type from frontmatter or cascaded from section. Determines which layout/template to use (e.g., "doc", "post", "page"). Cascaded from section _index.md if not specified in page frontmatter. |
variant |
str | None |
|
description |
str | None |
|
props |
dict[str, Any] |
|
section |
str | None |
Section path (e.g., "content/docs" or "docs"). Stored as path string, not Section object, for stability across rebuilds. None for root-level pages. |
file_hash |
str | None |
SHA256 hash of source file content. Used for cache validation to detect file changes. None during initial creation, populated during caching. Design Notes: - All fields are JSON-serializable (no object references) - Paths stored as strings (resolved to objects via registry on access) - Optional fields default to None (not all pages have all metadata) - No circular references (enables straightforward serialization) - No computed fields that require full content (those go in Page) Why Strings Instead of Path Objects? 1. JSON Serialization: Path objects cannot be directly JSON-serialized. Using strings allows cache files to be saved/loaded without custom handlers. 2. Cache Portability: String paths work across systems without Path object compatibility concerns (Windows vs Unix path separators handled by Path when converting back). 3. Type Consistency: PageMetadata IS PageCore (type alias). Cache expects strings, so PageCore must use strings for type compatibility. 4. Performance: String comparison for cache lookups is marginally faster than Path comparison (matters for incremental builds with 1000+ pages). Convert at boundaries: - Input: Path → str when creating PageCore (Page.post_init) - Output: str → Path when using paths (PageProxy, lookups) Cache Lifecycle: 1. Page created with PageCore during discovery 2. PageCore serialized to JSON and saved to cache 3. On incremental rebuild, PageCore loaded from cache 4. PageProxy wraps PageCore for lazy loading 5. Templates access fields via proxy properties (no load) 6. Full page loaded only if non-core field accessed |
aliases |
list[str] |
|
Performance |
— |
|
Methods 2
to_cache_dict
Serialize PageCore to cache-friendly dictionary.
Implements the Cacheable prot…
to_cache_dict
def to_cache_dict(self) -> dict[str, Any]
Serialize PageCore to cache-friendly dictionary.
Implements the Cacheable protocol for type-safe caching.
Returns
Dictionary with all PageCore fields, suitable for JSON serialization.
datetime fields are serialized as ISO-8601 strings.dict[str, Any]
—
from_cache_dict
classmethod
Deserialize PageCore from cache dictionary.
Implements the Cacheable protocol …
from_cache_dict
classmethod def from_cache_dict(cls, data: dict[str, Any]) -> PageCore
Deserialize PageCore from cache dictionary.
Implements the Cacheable protocol for type-safe caching.
Parameters 1
data |
dict[str, Any] |
Dictionary from cache (JSON-deserialized) |
Returns
Reconstructed PageCore instancePageCore
—
Internal Methods 1
__post_init__
Validate and normalize fields after initialization.
This runs automatically af…
__post_init__
def __post_init__(self) -> None
Validate and normalize fields after initialization.
This runs automatically after dataclass initialization.