|
3 | 3 | # Configuration reference: https://www.sphinx-doc.org/en/master/usage/configuration.html |
4 | 4 | # |
5 | 5 | import datetime |
6 | | -import os |
7 | 6 | import sys |
8 | 7 | from os.path import dirname |
9 | 8 |
|
|
33 | 32 | "sphinx_copybutton", |
34 | 33 | "sphinx.ext.autodoc", |
35 | 34 | "sphinx.ext.napoleon", |
| 35 | + "sphinxext.rediraffe", |
36 | 36 | ] |
37 | 37 | root_doc = "index" |
38 | 38 | source_suffix = [".md", ".rst"] |
|
64 | 64 | } |
65 | 65 |
|
66 | 66 |
|
67 | | -# -- Setup of redirects for internally relocated content -------------------- |
| 67 | +# -- Options for the rediraffe extension ------------------------------------- |
| 68 | +# ref: https://github.com/wpilibsuite/sphinxext-rediraffe#readme |
68 | 69 | # |
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. |
70 | 72 | # |
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