docs: add an extension to generate redirects
Reviewed-by: Eric Engestrom <eric@engestrom.ch> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5706>
This commit is contained in:

committed by
Marge Bot

parent
ce5a3524fa
commit
64a4ba9e1c
19
docs/_exts/redirects.py
Normal file
19
docs/_exts/redirects.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
redirects = []
|
||||||
|
|
||||||
|
def create_redirect(dst):
|
||||||
|
tpl = '<html><head><meta http-equiv="refresh" content="0; url={0}"><script>window.location.replace("{0}")</script></head></html>'
|
||||||
|
return tpl.format(dst)
|
||||||
|
|
||||||
|
def create_redirects(app, docname):
|
||||||
|
if not app.builder.name == 'html':
|
||||||
|
return
|
||||||
|
for src, dst in redirects:
|
||||||
|
path = os.path.join(app.outdir, '{0}.html'.format(src))
|
||||||
|
url = '{0}.html'.format(dst)
|
||||||
|
with open(path, 'w') as f:
|
||||||
|
f.write(create_redirect(url))
|
||||||
|
|
||||||
|
def setup(app):
|
||||||
|
app.connect('build-finished', create_redirects)
|
@@ -38,7 +38,7 @@ sys.path.append(os.path.abspath('_exts'))
|
|||||||
# Add any Sphinx extension module names here, as strings. They can be
|
# Add any Sphinx extension module names here, as strings. They can be
|
||||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||||
# ones.
|
# ones.
|
||||||
extensions = ['sphinx.ext.graphviz', 'formatting']
|
extensions = ['sphinx.ext.graphviz', 'formatting', 'redirects']
|
||||||
|
|
||||||
# Add any paths that contain templates here, relative to this directory.
|
# Add any paths that contain templates here, relative to this directory.
|
||||||
templates_path = ['_templates']
|
templates_path = ['_templates']
|
||||||
|
Reference in New Issue
Block a user