Skip to content

Commit 29bfbab

Browse files
committed
docs: use sphinx-rediraffe instead of custom script
1 parent fb40f8b commit 29bfbab

File tree

2 files changed

+13
-43
lines changed

2 files changed

+13
-43
lines changed

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ myst-parser
1010
pydata-sphinx-theme
1111
sphinx-autobuild
1212
sphinx-copybutton
13+
sphinxext-rediraffe

docs/source/conf.py

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Configuration reference: https://www.sphinx-doc.org/en/master/usage/configuration.html
44
#
55
import datetime
6-
import os
76
import sys
87
from os.path import dirname
98

@@ -33,6 +32,7 @@
3332
"sphinx_copybutton",
3433
"sphinx.ext.autodoc",
3534
"sphinx.ext.napoleon",
35+
"sphinxext.rediraffe",
3636
]
3737
root_doc = "index"
3838
source_suffix = [".md", ".rst"]
@@ -64,47 +64,16 @@
6464
}
6565

6666

67-
# -- Setup of redirects for internally relocated content --------------------
67+
# -- Options for the rediraffe extension -------------------------------------
68+
# ref: https://github.com/wpilibsuite/sphinxext-rediraffe#readme
6869
#
69-
# Each entry represent an `old` path that is now available at a `new` path
70+
# This extensions help us relocated content without breaking links. If a
71+
# document is moved internally, we should configure a redirect like below.
7072
#
71-
internal_redirects = [
72-
("turn-off.html", "zero-to-binderhub/turn-off.html"),
73-
("setup-registry.html", "zero-to-binderhub/setup-registry.html"),
74-
("setup-binderhub.html", "zero-to-binderhub/setup-binderhub.html"),
75-
("create-cloud-resources.html", "zero-to-binderhub/setup-prerequisites.html"),
76-
]
77-
internal_redirect_template = """
78-
<!DOCTYPE html>
79-
<html>
80-
<head>
81-
<title>Going to {new_url}</title>
82-
<link rel="canonical" href="{canonical_url}{new_url}"/>
83-
<meta name="robots" content="noindex">
84-
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
85-
<meta http-equiv="refresh" content="0; url={new_url}"/>
86-
</head>
87-
</html>
88-
"""
89-
90-
91-
def create_internal_redirects(app, docname):
92-
if app.builder.name in ("html", "readthedocs"):
93-
print(app.config["html_context"])
94-
canonical_url = app.config["html_context"].get("canonical_url", "")
95-
for old_name, new in internal_redirects:
96-
page = internal_redirect_template.format(
97-
new_url=new,
98-
canonical_url=canonical_url,
99-
)
100-
101-
target_path = app.outdir + "/" + old_name
102-
if not os.path.exists(os.path.dirname(target_path)):
103-
os.makedirs(os.path.dirname(target_path))
104-
105-
with open(target_path, "w") as f:
106-
f.write(page)
107-
108-
109-
def setup(app):
110-
app.connect("build-finished", create_internal_redirects)
73+
rediraffe_branch = "main"
74+
rediraffe_redirects = {
75+
"turn-off": "zero-to-binderhub/turn-off",
76+
"setup-registry": "zero-to-binderhub/setup-registry",
77+
"setup-binderhub": "zero-to-binderhub/setup-binderhub",
78+
"create-cloud-resources": "zero-to-binderhub/setup-prerequisites",
79+
}

0 commit comments

Comments
 (0)