|
18 | 18 |
|
19 | 19 | import sys
|
20 | 20 | import os
|
| 21 | +import tomllib |
21 | 22 | from pathlib import Path
|
22 | 23 |
|
23 |
| -import yaml |
| 24 | +from sphinx.application import Sphinx |
24 | 25 |
|
25 | 26 | DOCS_ROOT_DIR = Path(__file__).parent.resolve()
|
26 | 27 |
|
|
70 | 71 | 'notfound.extension',
|
71 | 72 | 'sphinx_antsibull_ext', # provides CSS for the plugin/module docs generated by antsibull
|
72 | 73 | 'sphinx_copybutton',
|
73 |
| - 'sphinx_reredirects', # redirects pages that have been restructured or removed |
74 | 74 | ]
|
75 | 75 |
|
76 | 76 | # Later on, add 'sphinx.ext.viewcode' to the list if you want to have
|
|
393 | 393 | linkcheck_workers = 25
|
394 | 394 | # linkcheck_anchors = False
|
395 | 395 |
|
396 |
| -# Generate redirects for pages that have been restructured or moved |
397 |
| -# if EXTRA_TAGS="-t redirects" is passed with the make invocation |
398 |
| -redirects = {} |
399 |
| -if tags.has('redirects'): |
400 |
| - redirects_config_path = DOCS_ROOT_DIR.parent / "ansible_redirects.yaml" |
401 |
| - redirect_keys = yaml.safe_load( |
402 |
| - redirects_config_path.read_text(encoding="utf-8") |
403 |
| - ) |
404 |
| - redirects = redirect_keys |
| 396 | +# Generate redirects for pages when building on Read The Docs |
| 397 | +def setup(app: Sphinx) -> dict[str, str]: |
| 398 | + |
| 399 | + if tags.has('redirects'): |
| 400 | + |
| 401 | + redirects = {} |
| 402 | + redirects_config_path = DOCS_ROOT_DIR.parent / "ansible_redirects.toml" |
| 403 | + with open(redirects_config_path, "rb") as f: |
| 404 | + redirects = tomllib.load(f) |
| 405 | + |
| 406 | + app.setup_extension('sphinx_reredirects') # redirect pages that have been restructured or removed |
| 407 | + app.config.redirects = redirects |
| 408 | + |
| 409 | + return { |
| 410 | + "parallel_read_safe": True, |
| 411 | + "parallel_write_safe": True, |
| 412 | + "version": app.config.release, |
| 413 | + } |
0 commit comments