Mesa (master): docs: add an extension to generate redirects
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Jul 7 11:04:13 UTC 2020
Module: Mesa
Branch: master
Commit: 64a4ba9e1ceeccbc7adeae368b5bc2553be88610
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=64a4ba9e1ceeccbc7adeae368b5bc2553be88610
Author: Erik Faye-Lund <erik.faye-lund at collabora.com>
Date: Thu Jul 2 12:14:28 2020 +0200
docs: add an extension to generate redirects
Reviewed-by: Eric Engestrom <eric at engestrom.ch>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5706>
---
docs/_exts/redirects.py | 19 +++++++++++++++++++
docs/conf.py | 2 +-
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/docs/_exts/redirects.py b/docs/_exts/redirects.py
new file mode 100644
index 00000000000..4eb7b855b58
--- /dev/null
+++ b/docs/_exts/redirects.py
@@ -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)
diff --git a/docs/conf.py b/docs/conf.py
index 27367654d47..5661fe0e0ae 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -38,7 +38,7 @@ sys.path.append(os.path.abspath('_exts'))
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
-extensions = ['sphinx.ext.graphviz', 'formatting']
+extensions = ['sphinx.ext.graphviz', 'formatting', 'redirects']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
More information about the mesa-commit
mailing list