|
158 | 158 | "sphinxcontrib.httpexample", |
159 | 159 | 'sphinxcontrib.googleanalytics', |
160 | 160 | "sphinxcontrib.video", |
161 | | - "sphinxext.opengraph", |
162 | 161 | "sphinx.ext.viewcode", |
163 | 162 | "sphinx.ext.autosummary", |
164 | 163 | "sphinx.ext.graphviz", |
165 | 164 | "sphinx_tabs.tabs", |
166 | 165 | "notfound.extension", |
| 166 | + "sphinx_reredirects", # URL redirects for documentation restructure |
| 167 | + "cel_lexer", # Custom CEL expression syntax highlighting |
| 168 | + "sphinxcontrib.mermaid", # Mermaid diagrams (flowcharts, sequence, state) |
167 | 169 | ] |
168 | 170 |
|
| 171 | +# Mermaid configuration |
| 172 | +# For offline/air-gapped builds, set MERMAID_OFFLINE=svg and install mermaid-cli: |
| 173 | +# npm install -g @mermaid-js/mermaid-cli |
| 174 | +# This will pre-render diagrams to SVG at build time (no JavaScript needed at runtime) |
| 175 | +_mermaid_offline = os.environ.get("MERMAID_OFFLINE", "") == "svg" |
| 176 | +mermaid_output_format = "svg" if _mermaid_offline else "raw" |
| 177 | +# Use puppeteer config for no-sandbox mode (required on Ubuntu 23.10+) |
| 178 | +mermaid_cmd = ["mmdc", "--puppeteerConfigFile", os.path.join(os.path.dirname(__file__), "_static/puppeteer-config.json")] |
| 179 | +mermaid_include_elk = False # Disable ELK layout to reduce dependencies |
| 180 | +mermaid_init_js = "" if _mermaid_offline else "mermaid.initialize({startOnLoad:true});" |
| 181 | + |
| 182 | +# Monkeypatch sphinxcontrib.mermaid to skip JS loading in offline/SVG mode |
| 183 | +if _mermaid_offline: |
| 184 | + import sphinxcontrib.mermaid |
| 185 | + _original_install_js = sphinxcontrib.mermaid.install_js |
| 186 | + def _patched_install_js(app, pagename, templatename, context, doctree): |
| 187 | + # Skip JS installation entirely when rendering to SVG |
| 188 | + if app.config.mermaid_output_format == "svg": |
| 189 | + return |
| 190 | + return _original_install_js(app, pagename, templatename, context, doctree) |
| 191 | + sphinxcontrib.mermaid.install_js = _patched_install_js |
| 192 | + |
| 193 | +# Some optional extensions depend on Pillow. In environments where Pillow cannot |
| 194 | +# be imported (for example, Python versions without compatible wheels), build |
| 195 | +# the documentation without those extensions. |
| 196 | +_pillow_available = True |
| 197 | +try: |
| 198 | + from PIL import Image # noqa: F401 |
| 199 | +except Exception as exc: # pragma: no cover - build-environment dependent |
| 200 | + _pillow_available = False |
| 201 | + _logger.warning("Pillow is not available (%s). Disabling sphinxext.opengraph.", exc) |
| 202 | + |
| 203 | +if _pillow_available: |
| 204 | + extensions.append("sphinxext.opengraph") |
| 205 | + |
169 | 206 | sphinx_tabs_disable_tab_closing = True |
170 | 207 | sphinx_tabs_disable_css_loading = True |
171 | 208 |
|
|
218 | 255 | "**/README.rst", |
219 | 256 | ] |
220 | 257 |
|
221 | | -html_js_files = ["patch_scrollToActive.js", "search_shortcut.js"] |
| 258 | +html_js_files = [ |
| 259 | + "patch_scrollToActive.js", |
| 260 | + "search_shortcut.js", |
| 261 | +] |
222 | 262 |
|
223 | 263 | html_extra_path = [ |
224 | 264 | "robots.txt", |
|
0 commit comments