Classes
OutputFormatsGenerator
Generates custom output formats for pages.
Provides alternative content formats to enable:
- Clien…
OutputFormatsGenerator
Generates custom output formats for pages.
Provides alternative content formats to enable:
- Client-side search via JSON index
- AI/LLM discovery via plain text
- Programmatic API access via JSON
Output Formats:
- Per-page JSON: page.json next to each page.html (metadata + content)
- Per-page LLM text: page.txt next to each page.html (AI-friendly format)
- Site-wide index.json: Searchable index of all pages with summaries
- Site-wide llm-full.txt: Full site content in single text file
This class acts as a facade, delegating to specialized generators:
- PageJSONGenerator: Per-page JSON files
- PageTxtGenerator: Per-page LLM text files
- SiteIndexGenerator: Site-wide index.json
- SiteLlmTxtGenerator: Site-wide llm-full.txt
Methods 1
generate
Generate all enabled output formats.
Checks configuration to determine which f…
generate
def generate(self) -> None
Generate all enabled output formats.
Checks configuration to determine which formats to generate, filters pages based on exclusion rules, then generates:
- Per-page formats (JSON, LLM text)
- Site-wide formats (index.json, llm-full.txt)
All file writes are atomic to prevent corruption during builds.
Internal Methods 4
__init__
Initialize output formats generator.
__init__
def __init__(self, site: Site, config: dict[str, Any] | None = None, graph_data: dict[str, Any] | None = None, build_context: BuildContext | Any | None = None) -> None
Initialize output formats generator.
Parameters 4
site |
Site |
Site instance |
config |
dict[str, Any] | None |
Configuration dict from bengal.toml |
graph_data |
dict[str, Any] | None |
Optional pre-computed graph data for including in page JSON |
build_context |
BuildContext | Any | None |
Optional BuildContext with accumulated JSON data from rendering phase |
_normalize_config
Normalize configuration to support both simple and advanced formats.
Simple fo…
_normalize_config
def _normalize_config(self, config: dict[str, Any]) -> dict[str, Any]
Normalize configuration to support both simple and advanced formats.
Simple format (from [build.output_formats]): { 'enabled': True, 'json': True, 'llm_txt': True, 'site_json': True, 'site_llm': True }
Advanced format (from [output_formats]): { 'enabled': True, 'per_page': ['json', 'llm_txt'], 'site_wide': ['index_json', 'llm_full'], 'options': {...} }
Parameters 1
config |
dict[str, Any] |
Returns
dict[str, Any]
_default_config
Return default configuration.
_default_config
def _default_config(self) -> dict[str, Any]
Return default configuration.
Returns
dict[str, Any]
_filter_pages
Filter pages based on exclusion rules.
Excludes pages that:
- Have no output p…
_filter_pages
def _filter_pages(self) -> list[Page]
Filter pages based on exclusion rules.
Excludes pages that:
- Have no output path (not rendered yet)
- Are in excluded sections
- Match excluded patterns (e.g., '404.html', 'search.html')
Returns
List of pages to include in output formatslist[Page]
—