Add sphinx extension that replaces absolut RTD urls

This makes it possible to add proper links when showing an rst on github,
while also resolving it to relative links on readthedocs
This commit is contained in:
Anders Ingemann 2015-04-12 13:18:10 +02:00
parent 62b87f22d5
commit 6980dd6517
3 changed files with 22 additions and 2 deletions

View file

@ -7,8 +7,8 @@ bootstrap-vz runs without any user intervention and
generates ready-to-boot images for a number of virtualization generates ready-to-boot images for a number of virtualization
platforms. platforms.
Its aim is to provide a reproducable bootstrapping process using Its aim is to provide a reproducable bootstrapping process using
`manifests <http://andsens.github.io/bootstrap-vz/manifest.html>`__ as `manifests <http://bootstrap-vz.readthedocs.org/en/master/manifest.html>`__
well as supporting a high degree of customizability through plugins. as well as supporting a high degree of customizability through plugins.
bootstrap-vz was coded from scratch in python once the bash script bootstrap-vz was coded from scratch in python once the bash script
architecture that was used in the architecture that was used in the

View file

@ -31,6 +31,7 @@ sys.path.insert(0, os.path.abspath(os.pardir))
extensions = ['sphinx.ext.coverage', extensions = ['sphinx.ext.coverage',
'sphinx.ext.autodoc', 'sphinx.ext.autodoc',
'sphinx.ext.linkcode', 'sphinx.ext.linkcode',
'docs.replace_rtd_links',
] ]
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.

19
docs/replace_rtd_links.py Normal file
View file

@ -0,0 +1,19 @@
def setup(app):
app.connect('doctree-resolved', replace_rtd_links)
return {'version': '0.1'}
def replace_rtd_links(app, doctree, fromdocname):
from docutils import nodes
import re
rtd_baseurl = 'http://bootstrap-vz.readthedocs.org/en/master/'
search = re.compile('^' + re.escape(rtd_baseurl) + '(.*)$')
for node in doctree.traverse(nodes.reference):
if 'refuri' not in node:
continue
if not node['refuri'].startswith(rtd_baseurl):
continue
node['refuri'] = re.sub(search, r'\1', node['refuri'])