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
indexPlugin: 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.glossaryPlugin: 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_indexandsite_glossary) are injected into the Chameleon template context only on pages declaring:page-role: indexor:page-role: glossary.
Enabling the Plugins
Add "index" and/or "glossary" to the plugins list in golem.toml:
[plugins]
plugins = [
"index",
"glossary",
]
Or in pyproject.toml:
[tool.golem.plugins]
plugins = [
"index",
"glossary",
]
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)
= 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)
= 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:
{
"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:
{
"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:
<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
<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
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
nameDefault value:
'index'cacheDefault value:
cache
init
def __init__(self, cache: Any = None, **extra: Any) -> None:
from_config
@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.
IndexPluginConfigured index plugin instance.
on_asg_created
@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.
NodeUnmodified ASG node.
compile_index
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
def reset(self) -> None:
Clear accumulated index entries.
NoneClears state in place with no return value.
on_build_start
@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.
NoneClears state in place.
on_template_context
@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.
PageContextEnriched template context containing
site_indexif role matches.
golem_mark_stale
@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] | NoneList of index aggregator pages to recompile, or
Noneif no invalidation is needed.
GlossaryPlugin
class GlossaryPlugin
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
nameDefault value:
'glossary'cacheDefault value:
cache
init
def __init__(self, cache: Any = None, **extra: Any) -> None:
from_config
@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.
GlossaryPluginConfigured glossary plugin instance.
on_asg_created
@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.
NodeUnmodified ASG node.
compile_glossary
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
def reset(self) -> None:
Clear accumulated glossary entries.
NoneClears state in place with no return value.
on_build_start
@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.
NoneClears state in place.
on_template_context
@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.
PageContextEnriched template context containing
site_glossaryif role matches.
golem_mark_stale
@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] | NoneList of glossary aggregator pages to recompile, or
Noneif no invalidation is needed.