Classes
ContentTypeStrategy
Base strategy for content type behavior.
Each content type (blog, doc, api-reference, etc.) can ha…
ContentTypeStrategy
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.
sort_pages
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
Sorted list of pages Default: Sort by weight (ascending), then title (alphabetical)list[Page]
—
filter_display_pages
Filter which pages to show in list views.
filter_display_pages
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
Filtered list of pages Default: Exclude the index page itselflist[Page]
—
should_paginate
Determine if this content type should use pagination.
should_paginate
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
True if pagination should be used Default: No pagination unless explicitly enabledbool
—
get_template
Determine which template to use for a page.
get_template
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
Template name (e.g., "blog/home.html", "doc/single.html") Default implementation provides sensible fallbacks: Note: For backward compatibility, if page is None, returns default_template.str
—
detect_from_section
Determine if this strategy applies to a section based on heuristics.
Override …
detect_from_section
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
True if this strategy should be used for this section Default: False (must be explicitly set)bool
—
Internal Methods 1
_get_type_name
Get the type name for this strategy (e.g., "blog", "doc").
_get_type_name
def _get_type_name(self) -> str
Get the type name for this strategy (e.g., "blog", "doc").
Returns
str