Module

postprocess.output_formats.json_generator

Per-page JSON generator for Bengal SSG.

Generates JSON files alongside each HTML page containing:

  • Page metadata (title, description, date, tags)
  • Content in multiple formats (HTML, plain text)
  • Reading statistics (word count, reading time)
  • Graph connections (for contextual minimap)

Classes

PageJSONGenerator
Generates per-page JSON files. Creates a JSON file alongside each HTML page containing metadata, c…
4

Generates per-page JSON files.

Creates a JSON file alongside each HTML page containing metadata, content, and graph connections for client-side features.

Methods 2

generate
Generate JSON files for all pages.
2 int
def generate(self, pages: list[Page], accumulated_json: list[tuple[Any, dict[str, Any]]] | None = None) -> int

Generate JSON files for all pages.

Parameters 2
pages list[Page]

List of pages to generate JSON for (used if accumulated_json not provided)

accumulated_json list[tuple[Any, dict[str, Any]]] | None

Optional pre-computed JSON data from rendering phase. If provided, uses this instead of iterating pages again.

Returns

int

Number of JSON files generated

page_to_json
Convert page to JSON representation.
4 dict[str, Any]
def page_to_json(self, page: Page, include_html: bool = True, include_text: bool = True, excerpt_length: int = 200) -> dict[str, Any]

Convert page to JSON representation.

Parameters 4
page Page

Page object

include_html bool

Include full HTML content

include_text bool

Include plain text content

excerpt_length int

Length of excerpt

Returns

dict[str, Any]

Dictionary suitable for JSON serialization

Internal Methods 2
__init__
Initialize the JSON generator.
4 None
def __init__(self, site: Site, graph_data: dict[str, Any] | None = None, include_html: bool = False, include_text: bool = True) -> None

Initialize the JSON generator.

Parameters 4
site Site

Site instance

graph_data dict[str, Any] | None

Optional pre-computed graph data for contextual minimap

include_html bool

Whether to include HTML content in JSON (default: False, HTML file already exists)

include_text bool

Whether to include plain text content in JSON (default: True)

_get_page_connections
Get filtered graph data showing only connections to the current page.
3 dict[str, Any] | None
def _get_page_connections(self, page: Page, graph_data: dict[str, Any], max_connections: int = 15) -> dict[str, Any] | None

Get filtered graph data showing only connections to the current page.

Parameters 3
page Page

Page object to get connections for

graph_data dict[str, Any]

Full graph data from GraphVisualizer.generate_graph_data()

max_connections int

Maximum number of connected nodes to include

Returns

dict[str, Any] | None

Filtered graph data with only current page and its connections, or None if page not in graph