1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
from __future__ import annotations
from typing import Any
from sphinx.addnodes import document
from sphinx.application import Sphinx
_CONFIG_VAR = "html_template_vars"
def update_context(
app: Sphinx,
pagename: str,
templatename: str,
context: dict[str, Any],
doctree: document,
) -> None:
for k, v in getattr(app.config, _CONFIG_VAR).items():
context[k] = v
def setup(app: Sphinx) -> None:
app.add_config_value(_CONFIG_VAR, {}, "")
app.connect("html-page-context", update_context)
|