Skip to content

Commit bd9f3ba

Browse files
Use sphinx_multiversion to make multiversioned docs
sphinx-multiversion can build a copy of the documentation for each tag and place in a subfolder. The existing spinx setup can build the top level latest version. versioning.html gives links to version in the sidebar. layout.html overrides the main template to use correct versions in the title and top navigation bar. Note this requires a patch to sphinx_multiversion to allow calling a prebuild command. This is used to call the docs_api for each checkout. sphinx-contrib/multiversion#62
1 parent 3cae2ec commit bd9f3ba

File tree

4 files changed

+56
-9
lines changed

4 files changed

+56
-9
lines changed

docs/_static/extra.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
div.versions {margin-top: 10px}

docs/_templates/layout.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{%- extends "!layout.html" %}
2+
{%- block htmltitle %}
3+
{% if versions %}
4+
<title>{{ title|striptags|e }} - {{ project }} {{ current_version.name }} Documentation</title>
5+
{% else %}
6+
<title>{{ title|striptags|e }}{{ titlesuffix }}</title>
7+
{% endif %}
8+
{%- endblock %}
9+
10+
{%- block rootrellink %}
11+
{% if versions %}
12+
<li class="nav-item nav-item-0"><a href="{{ pathto(master_doc)|e }}">{{ project }} {{ current_version.name }} Documentation</a>{{ reldelim1 }}</li>
13+
{% else %}
14+
<li class="nav-item nav-item-0"><a href="{{ pathto(master_doc)|e }}">{{ shorttitle|e }}</a>{{ reldelim1 }}</li>
15+
{% endif %}
16+
{%- endblock %}
17+

docs/_templates/versioning.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{% if versions %}
2+
<div class="versions">
3+
<h3>{{ _('Versions') }}</h3>
4+
<ul>
5+
<li><a href="../{{ pathto("",1)}}index.html">Latest</a></li>
6+
{%- for item in versions %}
7+
<li><a href="{{ item.url }}">{{ item.name }}</a></li>
8+
{%- endfor %}
9+
</ul>
10+
</div>
11+
{% else %}
12+
<div class="versions">
13+
<h3>{{ _('Versions') }}</h3>
14+
<ul>
15+
<li><a href="{{ pathto("",1)}}index.html">Latest</a></li>
16+
{%- for item in ['0.9.0', '1.0.0', '1.1.0', '2.0.0'] %}
17+
<li><a href="{{ pathto("",1)}}{{ item }}/index.html">{{ item }}</a></li>
18+
{%- endfor %}
19+
</ul>
20+
</div>
21+
{% endif %}

docs/conf.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,15 @@
3333
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3434
# ones.
3535
extensions = [
36-
'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.coverage',
37-
'sphinx.ext.viewcode', 'sphinx.ext.githubpages', 'sphinx.ext.imgmath'
36+
'sphinx.ext.autodoc',
37+
'sphinx.ext.doctest',
38+
'sphinx.ext.intersphinx',
39+
'sphinx.ext.todo',
40+
'sphinx.ext.coverage',
41+
'sphinx.ext.viewcode',
42+
'sphinx.ext.githubpages',
43+
'sphinx.ext.imgmath',
44+
'sphinx_multiversion',
3845
]
3946

4047
# Add any paths that contain templates here, relative to this directory.
@@ -87,13 +94,7 @@
8794
# a list of builtin themes.
8895
html_theme = 'classic'
8996

90-
html_sidebars = {
91-
'**': [
92-
'localtoc.html',
93-
'relations.html',
94-
'searchbox.html',
95-
]
96-
}
97+
html_sidebars = {'**': ['localtoc.html', 'relations.html', 'searchbox.html', 'versioning.html']}
9798

9899
# Theme options are theme-specific and customize the look and feel of a theme
99100
# further. For a list of options available for each theme, see the
@@ -106,6 +107,7 @@
106107
html_static_path = ['_static']
107108

108109
# -- Options for HTMLHelp output ------------------------------------------
110+
html_css_files = ['extra.css']
109111

110112
# Output file base name for HTML help builder.
111113
htmlhelp_basename = 'MantidImagingdoc'
@@ -158,3 +160,9 @@
158160

159161
# Stop sphinx from being a smartypants and merging the -- into a single unicode dash
160162
html_use_smartypants = False
163+
164+
# sphinx-multiversion
165+
smv_tag_whitelist = r'^\d+\.\d+\.\d+$' # tags that look like versions
166+
smv_branch_whitelist = None # No branches
167+
smv_released_pattern = r''
168+
smv_prebuild_command = "python setup.py docs_api"

0 commit comments

Comments
 (0)