Skip to content

Commit a490b19

Browse files
committed
doc: add version switcher flyout
Backport the bottom-left version switcher from unstable. Overrides the empty versions.html shipped by sphinx_rtd_theme 3.x with _templates/versions.html and populates html_context['versions']; styled by the theme CSS, toggled by theme.js.
1 parent 26adc2b commit a490b19

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

doc/_templates/versions.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{# Version switcher flyout.
2+
3+
sphinx_rtd_theme 3.x ships an empty versions.html (the flyout is injected by
4+
the ReadTheDocs addons when hosted there, and is absent on self-hosted
5+
builds). layout.html still does `{% include "versions.html" %}`, so this
6+
override revives the classic bottom-left "v: <version> ▾" widget. It is
7+
styled by the theme's existing .rst-versions CSS and toggled by theme.js;
8+
the entries come from html_context['versions'] in conf.py. #}
9+
{%- if versions %}
10+
<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="{{ _('Versions') }}">
11+
<span class="rst-current-version" data-toggle="rst-current-version">
12+
<span class="fa fa-book"> {{ _('Versions') }}</span>
13+
v: {{ current_version }}
14+
<span class="fa fa-caret-down"></span>
15+
</span>
16+
<div class="rst-other-versions">
17+
<dl>
18+
<dt>{{ _('Versions') }}</dt>
19+
{%- for slug, url in versions %}
20+
<dd><a href="{{ url }}">{{ slug }}</a></dd>
21+
{%- endfor %}
22+
</dl>
23+
</div>
24+
</div>
25+
{%- endif %}

doc/conf.py.in

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,22 @@ html_theme_options = {
9292

9393
html_show_sphinx = True
9494
nbsphinx_allow_errors = True
95-
html_context = {'header_title': '@PROJECT_NAME@'}
95+
html_context = {
96+
'header_title': '@PROJECT_NAME@',
97+
# Version switcher flyout (rendered by _templates/versions.html, which
98+
# overrides the empty versions.html shipped by sphinx_rtd_theme 3.x). The
99+
# list is static -- update it when a new release line is published.
100+
# display_lower_left enables the flyout on older theme versions that gate
101+
# the include on it; harmless on 3.x.
102+
'display_lower_left': True,
103+
'current_version': version,
104+
'versions': [
105+
['latest', 'https://triqs.github.io/solid_dmft/latest/'],
106+
['unstable', 'https://triqs.github.io/solid_dmft/unstable/'],
107+
['4.0.x', 'https://triqs.github.io/solid_dmft/4.0.x/'],
108+
['3.3.x', 'https://triqs.github.io/solid_dmft/3.3.x/'],
109+
],
110+
}
96111
html_static_path = ['@CMAKE_CURRENT_SOURCE_DIR@/_static']
97112
html_sidebars = {'index': ['sideb.html', 'searchbox.html']}
98113

0 commit comments

Comments
 (0)