diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2019-10-30 17:41:10 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2019-10-30 17:41:10 +0100 |
| commit | 1920c5cee79f258a69f1000124fd6fbde20f1490 (patch) | |
| tree | 7a2f3d3928d1079fb02e17feeadffa128022aaeb | |
| parent | 6ce8ef30389480b3fabc3991bdf2b476d9435b60 (diff) | |
| download | PROJ-1920c5cee79f258a69f1000124fd6fbde20f1490.tar.gz PROJ-1920c5cee79f258a69f1000124fd6fbde20f1490.zip | |
Doc: add a redirects extension, and make a projjson.html redirect at the top to its current location
| -rw-r--r-- | docs/source/_extensions/redirects.py | 39 | ||||
| -rw-r--r-- | docs/source/conf.py | 5 |
2 files changed, 44 insertions, 0 deletions
diff --git a/docs/source/_extensions/redirects.py b/docs/source/_extensions/redirects.py new file mode 100644 index 00000000..6a59b622 --- /dev/null +++ b/docs/source/_extensions/redirects.py @@ -0,0 +1,39 @@ +import os + +# https://tech.signavio.com/2017/managing-sphinx-redirects + + +template="""<html> + <head> + <meta http-equiv="refresh" content="1; url=%s" /> + <script> + window.location.href = "%s" + </script> + </head> +</html>""" + + +def gather_redirects(): + output = {} + + output.update({ 'projjson.html' : 'usage/projjson.html' }) + return output + +from shutil import copyfile +# copy legacy redirects +def copy_legacy_redirects(app, docname): # Sphinx expects two arguments + if app.builder.name == 'html': + for key in app.config.redirect_files: + src = key + tgt = app.config.redirect_files[key] + html = template % (tgt, tgt) + with open(os.path.join(app.outdir, src), 'wb') as f: + f.write(html.encode('utf-8')) + f.close() + + + +def setup(app): + app.add_config_value('redirect_files', {}, 'html') + app.connect('build-finished', copy_legacy_redirects) + return { 'parallel_read_safe': False, 'parallel_write_safe': True } diff --git a/docs/source/conf.py b/docs/source/conf.py index 243c93b7..cd004777 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -20,6 +20,7 @@ import datetime # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.insert(0, os.path.abspath('.')) +sys.path.insert(0, os.path.abspath('_extensions')) import bibstyle @@ -35,6 +36,7 @@ extensions = [ 'sphinx.ext.mathjax', 'sphinxcontrib.bibtex', 'breathe', + 'redirects', ] # Add any paths that contain templates here, relative to this directory. @@ -370,3 +372,6 @@ texinfo_documents = [ breathe_projects = { "cpp_stuff":"../build/xml/", } + +import redirects +redirect_files = redirects.gather_redirects() |
