|
1 | 1 | from datetime import date |
2 | 2 |
|
| 3 | +from sphinx.application import Sphinx |
| 4 | + |
| 5 | +# Constants |
| 6 | +CLP_GIT_REF = "main" |
| 7 | + |
| 8 | + |
3 | 9 | # -- Project information ------------------------------------------------------- |
4 | 10 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information |
5 | 11 |
|
|
79 | 85 | "show_prev_next": False, |
80 | 86 | "switcher": { |
81 | 87 | "json_url": "https://docs.yscope.com/_static/clp-versions.json", |
82 | | - "version_match": "main", |
| 88 | + "version_match": CLP_GIT_REF, |
83 | 89 | }, |
84 | 90 | "use_edit_page_button": True, |
85 | 91 | } |
|
90 | 96 | html_context = { |
91 | 97 | "github_user": "y-scope", |
92 | 98 | "github_repo": "clp", |
93 | | - "github_version": "main", |
| 99 | + "github_version": CLP_GIT_REF, |
94 | 100 | "doc_path": "docs/src", |
95 | 101 | } |
96 | 102 |
|
|
99 | 105 | # https://pydata-sphinx-theme.readthedocs.io/en/stable/user_guide/static_assets.html |
100 | 106 |
|
101 | 107 |
|
102 | | -def setup(app): |
| 108 | +def setup(app: Sphinx) -> None: |
103 | 109 | app.add_css_file("custom.css") |
| 110 | + |
| 111 | + app.connect("source-read", _replace_variable_placeholders) |
| 112 | + |
| 113 | + |
| 114 | +def _replace_variable_placeholders(_app: Sphinx, _docname: str, content: list[str]) -> None: |
| 115 | + """ |
| 116 | + Replaces each variable placeholder in the docs with the relevant value. |
| 117 | +
|
| 118 | + :param _app: |
| 119 | + :param _docname: |
| 120 | + :param content: The content of the doc in a list with a single element. |
| 121 | + """ |
| 122 | + placeholder_to_value = { |
| 123 | + "DOCS_VAR_CLP_GIT_REF": CLP_GIT_REF, |
| 124 | + } |
| 125 | + for placeholder, value in placeholder_to_value.items(): |
| 126 | + content[0] = content[0].replace(placeholder, value) |
0 commit comments