Skip to main content

Golem Documentation

Michael Bernstein

Index & Glossary Plugins

The index and glossary plugins provide automated compilation of site-wide, alphabetized back-of-the-book indexes and terminological glossaries from standard AsciiDoc syntax.

Overview

  • index Plugin: Scans all documentation pages during the ASG build stage, collecting inline `
    `, `
    term
    `, and `
    primary, secondary, tertiary
    ` macros. It compiles an alphabetized, three-tier hierarchical index mapping terms to source document paths.
  • glossary Plugin: Scans description lists marked with the [glossary] attribute across all pages, extracting defined terms and explanations into a unified alphabetized glossary.
  • Role-Based Context Injection: To maintain lean template scopes, the compiled data structures (site_index and site_glossary) are injected into the Chameleon template context only on pages declaring :page-role: index or :page-role: glossary.

Enabling the Plugins

Add "index" and/or "glossary" to the plugins list in golem.toml:

golem.toml
TOML
[plugins]
plugins = [
    "index",
    "glossary",
]

Or in pyproject.toml:

pyproject.toml
TOML
[tool.golem.plugins]
plugins = [
    "index",
    "glossary",
]

Authoring Syntax

Document Index Terms

Golem recognizes standard AsciiDoc index syntax anywhere within document prose:

  • Primary Index Terms:
    ASCIIDOC
    The compiler uses an indexterm:[Abstract Semantic Graph] to resolve nodes.
    
    You can also use double parentheses ((ASG)) for inline primary terms.
  • Hierarchical Multi-Level Terms (Primary, Secondary, Tertiary):

+ Triple parentheses or indexterm2:[...] declare multi-level index relationships: +

ASCIIDOC
We configure caching policies (((caching, disk cache, TTL))) in the server layer.

+ This registers the term under C -> caching -> disk cache -> TTL.

Glossary Definition Lists

To register glossary terms, create standard AsciiDoc description lists annotated with the [glossary] attribute:

docs/concepts/architecture.adoc
ASCIIDOC
[glossary]
Abstract Syntax Tree (AST)::
  The initial parse tree produced by Lark before semantic resolution.

Abstract Semantic Graph (ASG)::
  The resolved graph of typed document nodes produced by AsciiDoctrine.

TAL::
  Template Attribute Language; declarative XML attributes used by Chameleon.
Abstract Syntax Tree (AST)

The initial parse tree produced by Lark before semantic resolution.

Abstract Semantic Graph (ASG)

The resolved graph of typed document nodes produced by AsciiDoctrine.

TAL

Template Attribute Language; declarative XML attributes used by Chameleon.

Terms defined in [glossary] lists across all documentation files are aggregated into the global glossary dictionary.

Dedicated Index & Glossary Pages

To render the compiled index or glossary on a page, create an AsciiDoc file with the corresponding :page-role: attribute in its header:

Index Page (docs/index-terms.adoc)

docs/index-terms.adoc
ASCIIDOC
= Document Index
:page-role: index

Index terms compiled across this publication.

When :page-role: index is present, Golem's index plugin populates site_index in the template context.

Glossary Page (docs/glossary.adoc)

docs/glossary.adoc
ASCIIDOC
= Project Glossary
:page-role: glossary

Comprehensive dictionary of project terminology and definitions.

When :page-role: glossary is present, Golem's glossary plugin populates site_glossary in the template context.

Template Context Structures

site_index Data Structure

site_index is an alphabetized dictionary mapping capital letter headers to primary terms:

PYTHON
{
    "A": {
        "Abstract Semantic Graph": {
            "locations": ["docs/pipeline.adoc", "docs/plugins.adoc"],
            "secondary": {
                "resolution": {
                    "locations": ["docs/pipeline.adoc"],
                    "secondary": {},
                }
            }
        }
    }
}

site_glossary Data Structure

site_glossary is an alphabetized dictionary mapping capital letter headers to lists of term entries:

PYTHON
{
    "A": [
        {
            "term": "Abstract Semantic Graph (ASG)",
            "definition": "The resolved graph of typed document nodes...",
            "doc_path": "docs/concepts/architecture.adoc",
        }
    ]
}

Chameleon TAL Rendering Examples

Rendering the Index Page

In your custom theme or page template:

HTML
<div tal:condition="site_index | nothing" class="site-index">
    <div tal:repeat="letter site_index" class="index-section">
        <h2 class="index-letter">${letter}</h2>
        <ul class="index-primary-list">
            <li tal:repeat="term python: sorted(site_index[letter].keys())">
                <span class="index-term">${term}</span>
                <span class="index-locations" tal:condition="site_index[letter][term]['locations']">
                    (Page: 
                    <span tal:repeat="loc site_index[letter][term]['locations']">
                        <a href="${loc.replace('.adoc', '.html')}">${loc}</a>
                    </span>)
                </span>
                <!-- Secondary subterms -->
                <ul tal:condition="site_index[letter][term]['secondary']" class="index-secondary-list">
                    <li tal:repeat="sec_term python: sorted(site_index[letter][term]['secondary'].keys())">
                        <span class="index-subterm">${sec_term}</span>
                    </li>
                </ul>
            </li>
        </ul>
    </div>
</div>

Rendering the Glossary Page

HTML
<div tal:condition="site_glossary | nothing" class="site-glossary">
    <div tal:repeat="letter site_glossary" class="glossary-section">
        <h2 class="glossary-letter">${letter}</h2>
        <dl class="glossary-list">
            <tal:block tal:repeat="entry site_glossary[letter]">
                <dt id="glossary-${entry['term'].lower().replace(' ', '-')}">
                    ${entry['term']}
                </dt>
                <dd>${entry['definition']}</dd>
            </tal:block>
        </dl>
    </div>
</div>

API Reference

IndexPlugin

class IndexPlugin

PYTHON
class IndexPlugin(GolemPlugin):

Collect and compile index terms across documentation pages.

Traverses ASG documents for IndexTerm occurrences, accumulating primary, secondary, and tertiary terms with their source document paths, and produces alphabetized hierarchical index structures.

Attributes

name

Default value: 'index'

cache

Default value: cache

init

PYTHON
def __init__(self, cache: Any = None, **extra: Any) -> None:

from_config

PYTHON
@classmethod
def from_config(cls, config: Any = None) -> IndexPlugin:

Construct an IndexPlugin instance from configuration.

config (Any, optional)

Site configuration object or dictionary. Defaults to None.

IndexPlugin

Configured index plugin instance.

on_asg_created

PYTHON
@hookimpl
def on_asg_created(self, asg: Node, doc_path: Path | None = None) -> Node:

Walk the ASG collecting IndexTerm nodes, accumulating into self._entries.

asg (Node)

Root ASG document node to inspect.

doc_path (Path | None, optional)

Path to the documentation source file.

Node

Unmodified ASG node.

compile_index

PYTHON
def compile_index(self) -> dict[str, dict[str, Any]]:

Return alphabetized hierarchical index compiled from collected terms.

dict[str, dict[str, Any]]

Nested dictionary mapping first letters to term entries and subterms.

reset

PYTHON
def reset(self) -> None:

Clear accumulated index entries.

None

Clears state in place with no return value.

on_build_start

PYTHON
@hookimpl
def on_build_start(self, config: Any = None) -> None:

Reset state at the beginning of each build run.

config (Any, optional)

Site configuration object. Defaults to None.

None

Clears state in place.

on_template_context

PYTHON
@hookimpl
def on_template_context(self, context: PageContext, doc_path: Path) -> PageContext:

Inject compiled index into template context if page declares index role.

context (PageContext)

Chameleon template context dictionary.

doc_path (Path)

Path to the documentation source file being processed.

PageContext

Enriched template context containing site_index if role matches.

golem_mark_stale

PYTHON
@hookimpl
def golem_mark_stale(self, changed_files: list[Path], cache_metadata: dict[str, dict[str, Any]]) -> list[Path] | None:

Register index aggregator pages for recompilation when documents with index terms change.

changed_files (list[Path])

List of file paths directly modified or deleted in the current build cycle.

cache_metadata (dict[str, dict[str, Any]])

Cached build metadata mapping file paths to node types and attributes.

list[Path] | None

List of index aggregator pages to recompile, or None if no invalidation is needed.

GlossaryPlugin

class GlossaryPlugin

PYTHON
class GlossaryPlugin(GolemPlugin):

Collect and compile glossary definitions across documentation pages.

Traverses ASG documents for description list blocks annotated with [glossary], accumulating term definitions with their origin document paths, and produces alphabetized glossary collections.

Attributes

name

Default value: 'glossary'

cache

Default value: cache

init

PYTHON
def __init__(self, cache: Any = None, **extra: Any) -> None:

from_config

PYTHON
@classmethod
def from_config(cls, config: Any = None) -> GlossaryPlugin:

Construct a GlossaryPlugin instance from configuration.

config (Any, optional)

Site configuration object or dictionary. Defaults to None.

GlossaryPlugin

Configured glossary plugin instance.

on_asg_created

PYTHON
@hookimpl
def on_asg_created(self, asg: Node, doc_path: Path | None = None) -> Node:

Walk the ASG collecting glossary definition list entries.

asg (Node)

Root ASG document node to inspect.

doc_path (Path | None, optional)

Path to the documentation source file.

Node

Unmodified ASG node.

compile_glossary

PYTHON
def compile_glossary(self) -> dict[str, list[GlossaryEntry]]:

Return alphabetized glossary compiled from collected definition lists.

dict[str, list[GlossaryEntry]]

Grouped dictionary mapping first letters to term entries.

reset

PYTHON
def reset(self) -> None:

Clear accumulated glossary entries.

None

Clears state in place with no return value.

on_build_start

PYTHON
@hookimpl
def on_build_start(self, config: Any = None) -> None:

Reset state at the beginning of each build run.

config (Any, optional)

Site configuration object. Defaults to None.

None

Clears state in place.

on_template_context

PYTHON
@hookimpl
def on_template_context(self, context: PageContext, doc_path: Path) -> PageContext:

Inject compiled glossary into template context if page declares glossary role.

context (PageContext)

Chameleon template context dictionary.

doc_path (Path)

Path to the documentation source file being processed.

PageContext

Enriched template context containing site_glossary if role matches.

golem_mark_stale

PYTHON
@hookimpl
def golem_mark_stale(self, changed_files: list[Path], cache_metadata: dict[str, dict[str, Any]]) -> list[Path] | None:

Register glossary aggregator pages for recompilation when documents with glossary definitions change.

changed_files (list[Path])

List of file paths directly modified or deleted in the current build cycle.

cache_metadata (dict[str, dict[str, Any]])

Cached build metadata mapping file paths to node types and attributes.

list[Path] | None

List of glossary aggregator pages to recompile, or None if no invalidation is needed.