Module

postprocess.output_formats

Output formats generation package for Bengal SSG.

Generates alternative output formats for pages to enable:

  • Client-side search (JSON index)
  • AI/LLM discovery (plain text format)
  • Programmatic access (JSON API)

Structure:

  • json_generator.py: Per-page JSON files
  • txt_generator.py: Per-page LLM text files
  • index_generator.py: Site-wide index.json
  • llm_generator.py: Site-wide llm-full.txt
  • utils.py: Shared utilities

Configuration (bengal.toml): [output_formats] enabled = true per_page = ["json", "llm_txt"] site_wide = ["index_json", "llm_full"]

Classes

OutputFormatsGenerator
Generates custom output formats for pages. Provides alternative content formats to enable: - Clien…
5

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…
0 None
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:

  1. Per-page formats (JSON, LLM text)
  2. 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.
4 None
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…
1 dict[str, Any]
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.
0 dict[str, Any]
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…
0 list[Page]
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[Page]

List of pages to include in output formats