Module

core.page.computed

Page Computed Properties Mixin - Cached expensive computations.

Classes

HasMetadata
Protocol for objects that have metadata and content attributes.
0

Protocol for objects that have metadata and content attributes.

Inherits from Protocol

Attributes

Name Type Description
metadata dict[str, Any]
content str
PageComputedMixin
Mixin providing cached computed properties for pages. This mixin handles expensive operations that…
3

Mixin providing cached computed properties for pages.

This mixin handles expensive operations that are cached after first access:

  • meta_description - SEO-friendly description
  • reading_time - Estimated reading time
  • excerpt - Content excerpt

Methods 3

meta_description property
Generate SEO-friendly meta description (computed once, cached). Creates descri…
str
def meta_description(self: HasMetadata) -> str

Generate SEO-friendly meta description (computed once, cached).

Creates description by:

  • Using explicit 'description' from metadata if available
  • Otherwise generating from content by stripping HTML and truncating
  • Attempting to end at sentence boundary for better readability

The result is cached after first access, so multiple template uses (meta tag, og:description, twitter:description) only compute once.

Returns

str

Meta description text (max 160 chars)

reading_time property
Calculate reading time in minutes (computed once, cached). Estimates reading t…
int
def reading_time(self: HasMetadata) -> int

Calculate reading time in minutes (computed once, cached).

Estimates reading time based on word count at 200 words per minute. Strips HTML before counting to ensure accurate word count.

The result is cached after first access for efficient repeated use.

Returns

int

Reading time in minutes (minimum 1)

excerpt property
Extract content excerpt (computed once, cached). Creates a 200-character excer…
str
def excerpt(self: HasMetadata) -> str

Extract content excerpt (computed once, cached).

Creates a 200-character excerpt from content by:

  • Stripping HTML tags
  • Truncating to length
  • Respecting word boundaries (doesn't cut words in half)
  • Adding ellipsis if truncated

The result is cached after first access for efficient repeated use.

Returns

str

Excerpt text with ellipsis if truncated