Module

content_types.base

Base strategy class for content types.

Defines the interface that all content type strategies must implement.

Classes

ContentTypeStrategy
Base strategy for content type behavior. Each content type (blog, doc, api-reference, etc.) can ha…
6

Base strategy for content type behavior.

Each content type (blog, doc, api-reference, etc.) can have its own strategy that defines:

  • How pages are sorted
  • What pages are shown in list views
  • Whether pagination is used
  • What template to use

Methods 5

sort_pages
Sort pages for display in list views.
1 list[Page]
def sort_pages(self, pages: list[Page]) -> list[Page]

Sort pages for display in list views.

Parameters 1
pages list[Page]

List of pages to sort

Returns

list[Page]

Sorted list of pages

Default: Sort by weight (ascending), then title (alphabetical)

filter_display_pages
Filter which pages to show in list views.
2 list[Page]
def filter_display_pages(self, pages: list[Page], index_page: Page | None = None) -> list[Page]

Filter which pages to show in list views.

Parameters 2
pages list[Page]

All pages in the section

index_page Page | None

The section's index page (to exclude from lists)

Returns

list[Page]

Filtered list of pages

Default: Exclude the index page itself

should_paginate
Determine if this content type should use pagination.
2 bool
def should_paginate(self, page_count: int, config: dict[str, Any]) -> bool

Determine if this content type should use pagination.

Parameters 2
page_count int

Number of pages in section

config dict[str, Any]

Site configuration

Returns

bool

True if pagination should be used

Default: No pagination unless explicitly enabled

get_template
Determine which template to use for a page.
2 str
def get_template(self, page: Page | None = None, template_engine: Any | None = None) -> str

Determine which template to use for a page.

Parameters 2
page Page | None

Page to get template for (optional for backward compatibility)

template_engine Any | None

Template engine for checking template existence (optional)

Returns

str

Template name (e.g., "blog/home.html", "doc/single.html")

Default implementation provides sensible fallbacks:

  • Home pages: try {type}/home.html, then home.html, then index.html
  • Section indexes: try {type}/list.html, then list.html
  • Regular pages: try {type}/single.html, then single.html

Note: For backward compatibility, if page is None, returns default_template.

detect_from_section
Determine if this strategy applies to a section based on heuristics. Override …
1 bool
def detect_from_section(self, section: Section) -> bool

Determine if this strategy applies to a section based on heuristics.

Override this in subclasses to provide auto-detection logic.

Parameters 1
section Section

Section to analyze

Returns

bool

True if this strategy should be used for this section

Default: False (must be explicitly set)

Internal Methods 1
_get_type_name
Get the type name for this strategy (e.g., "blog", "doc").
0 str
def _get_type_name(self) -> str

Get the type name for this strategy (e.g., "blog", "doc").

Returns

str