Skip to content

Commit acdbce4

Browse files
committed
conditionally load extension
1 parent 34ed153 commit acdbce4

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

docs/docsite/rst/conf.py

+20-11
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818

1919
import sys
2020
import os
21+
import tomllib
2122
from pathlib import Path
2223

23-
import yaml
24+
from sphinx.application import Sphinx
2425

2526
DOCS_ROOT_DIR = Path(__file__).parent.resolve()
2627

@@ -70,7 +71,6 @@
7071
'notfound.extension',
7172
'sphinx_antsibull_ext', # provides CSS for the plugin/module docs generated by antsibull
7273
'sphinx_copybutton',
73-
'sphinx_reredirects', # redirects pages that have been restructured or removed
7474
]
7575

7676
# Later on, add 'sphinx.ext.viewcode' to the list if you want to have
@@ -393,12 +393,21 @@
393393
linkcheck_workers = 25
394394
# linkcheck_anchors = False
395395

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

Comments
 (0)