Skip to content

Commit 0fd40b9

Browse files
AndreFCruzclaude
andauthored
docs(sphinx): render version + add home to sidebar (#34)
sphinx_rtd_theme >=3.0 dropped the `display_version` option, so the previous setting in conf.py was a no-op. Override the upstream `sidebartitle` block to render `{{ version }}` between the project link and the search box, and add a matching `.version` style. Also add a `Home <self>` toctree entry so the landing page is reachable from the sidebar, and prefix each entry with a small emoji. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c7709d1 commit 0fd40b9

4 files changed

Lines changed: 54 additions & 10 deletions

File tree

docs/_static/custom.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* Version label rendered by docs/_templates/layout.html under the project
2+
title in the sidebar. sphinx_rtd_theme >=3.0 no longer ships a `.version`
3+
style, so we provide one matching the prior look. */
4+
.wy-side-nav-search > .version {
5+
color: rgba(255, 255, 255, 0.45);
6+
font-size: 90%;
7+
margin-top: -0.4045em;
8+
margin-bottom: 0.809em;
9+
font-weight: normal;
10+
display: block;
11+
}

docs/_templates/layout.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{# sphinx_rtd_theme >=3.0 dropped the `display_version` switch from its sidebar
2+
template. We re-add a small version line under the project title by
3+
overriding the upstream `sidebartitle` block. The body mirrors the upstream
4+
block (sphinx_rtd_theme/layout.html) so we can slot in the `.version` div
5+
between the project link and the searchbox. #}
6+
{% extends "!layout.html" %}
7+
8+
{% block sidebartitle %}
9+
{%- set _logo_url = logo_url|default(pathto('_static/' + (logo or ""), 1)) %}
10+
{%- set _root_doc = root_doc|default(master_doc) %}
11+
<a href="{{ pathto(_root_doc) }}"{% if not theme_logo_only %} class="icon icon-home"{% endif %}>
12+
{% if not theme_logo_only %}{{ project }}{% endif %}
13+
{%- if logo or logo_url %}
14+
<img src="{{ _logo_url }}" class="logo" alt="{{ _('Logo') }}"/>
15+
{%- endif %}
16+
</a>
17+
18+
{%- if version %}
19+
<div class="version">{{ version }}</div>
20+
{%- endif %}
21+
22+
{%- if READTHEDOCS or DEBUG %}
23+
{%- if theme_version_selector or theme_language_selector %}
24+
<div class="switch-menus">
25+
<div class="version-switch"></div>
26+
<div class="language-switch"></div>
27+
</div>
28+
{%- endif %}
29+
{%- endif %}
30+
31+
{%- include "searchbox.html" %}
32+
{% endblock %}

docs/conf.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@
6161
html_js_files = [
6262
'custom.js', # custom JS file
6363
]
64+
html_css_files = [
65+
'custom.css', # custom CSS file
66+
]
6467

65-
# Show the package version in the sidebar header (under the project title).
66-
# `release` (set above) is the source; `display_version=True` is the
67-
# sphinx_rtd_theme switch that renders it.
68-
html_theme_options = {
69-
'display_version': True,
70-
}
68+
# The package version is rendered under the project title in the sidebar via
69+
# `_templates/layout.html`, which overrides sphinx_rtd_theme's `sidebartitle`
70+
# block. The theme's old `display_version` option was removed in 3.0.
7171

7272
# nbsphinx configuration
7373
nbsphinx_execute = 'never' # Set to 'always' if you want to execute the notebooks during the build process

docs/index.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ Check out the following sub-pages:
3333
.. toctree::
3434
:maxdepth: 1
3535

36-
Readme file <readme>
37-
Updates <updates>
38-
API reference <source/modules>
39-
Example notebooks <notebooks>
36+
🏠 Home <self>
37+
📖 Readme file <readme>
38+
📝 Updates <updates>
39+
⚙️ API reference <source/modules>
40+
📓 Example notebooks <notebooks>
4041

4142

4243
Citing

0 commit comments

Comments
 (0)