|
18 | 18 |
|
19 | 19 | import sys
|
20 | 20 | import os
|
| 21 | +import tomllib |
| 22 | +from pathlib import Path |
| 23 | + |
| 24 | +from sphinx.application import Sphinx |
| 25 | + |
| 26 | +DOCS_ROOT_DIR = Path(__file__).parent.resolve() |
21 | 27 |
|
22 | 28 | # If your extensions are in another directory, add it here. If the directory
|
23 | 29 | # is relative to the documentation root, use os.path.abspath to make it
|
|
376 | 382 | autoclass_content = 'both'
|
377 | 383 |
|
378 | 384 | # Note: Our strategy for intersphinx mappings is to have the upstream build location as the
|
379 |
| -# canonical source. |
| 385 | +# canonical source. |
380 | 386 | intersphinx_mapping = {
|
381 | 387 | 'python': ('https://docs.python.org/2/', None),
|
382 | 388 | 'python3': ('https://docs.python.org/3/', None),
|
|
390 | 396 | ]
|
391 | 397 | linkcheck_workers = 25
|
392 | 398 | # linkcheck_anchors = False
|
| 399 | + |
| 400 | +# Generate redirects for pages when building on Read The Docs |
| 401 | +def setup(app: Sphinx) -> dict[str, bool | str]: |
| 402 | + |
| 403 | + if 'redirects' in app.tags: |
| 404 | + |
| 405 | + redirects_config_path = DOCS_ROOT_DIR.parent / "declarative-configs" / "ansible_redirects.toml" |
| 406 | + redirects = tomllib.loads(redirects_config_path.read_text()) |
| 407 | + redirect_template = DOCS_ROOT_DIR.parent / ".templates" / "redirect_template.html" |
| 408 | + |
| 409 | + app.config.redirects = redirects |
| 410 | + app.config.redirect_html_template_file = redirect_template |
| 411 | + app.setup_extension('sphinx_reredirects') # redirect pages that have been restructured or removed |
| 412 | + |
| 413 | + return { |
| 414 | + "parallel_read_safe": True, |
| 415 | + "parallel_write_safe": True, |
| 416 | + "version": app.config.release, |
| 417 | + } |
0 commit comments