Skip to content

Commit fbc20f3

Browse files
committed
add ansible_redirects in-tree extension
1 parent 1c7e99f commit fbc20f3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""Sphinx extension for generating redirects in Ansible package docs."""
2+
3+
import os
4+
from pathlib import Path
5+
6+
import yaml
7+
from sphinx.application import Sphinx
8+
9+
DOCSITE_ROOT_DIR = Path(__file__).parents[1].resolve()
10+
ANSIBLE_REDIRECTS_CONFIG_PATH = DOCSITE_ROOT_DIR / "ansible_redirects.yaml"
11+
REDIRECT_KEYS = yaml.safe_load(
12+
ANSIBLE_REDIRECTS_CONFIG_PATH.read_text(encoding="utf-8")
13+
)
14+
ENABLE_REDIRECTS = os.environ.get("ENABLE_REDIRECTS", "false").lower() in {"1", "true"}
15+
16+
17+
def setup(app: Sphinx):
18+
app.setup_extension("sphinx_reredirects")
19+
20+
if ENABLE_REDIRECTS:
21+
app.config.redirects = REDIRECT_KEYS
22+
23+
return {
24+
"parallel_read_safe": True,
25+
"parallel_write_safe": True,
26+
"version": app.config.release,
27+
}

0 commit comments

Comments
 (0)