Skip to content

Commit 4e8560d

Browse files
authored
Add the version string to the sidebar in the HTML docs (#95)
* Add the version string to the sidebar in the HTML docs This is useful because Read the Docs doesn't show the current version for "latest" or "stable". Having the exact version, down to commit, etc. is useful! * Pin Furo to ensure compatibility of custom CSS & templates
1 parent 8e99c8b commit 4e8560d

6 files changed

Lines changed: 46 additions & 3 deletions

File tree

docs/conf.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33

44
from datetime import date
55

6+
import setuptools_scm
7+
68
# -- Project information ------------------------------------------------------
79

810
project = "docstub"
9-
copyright = f"{date.today().year}, docstub contributors"
11+
12+
version = setuptools_scm.get_version(search_parent_directories=True)
13+
version = f"v{version}"
14+
version = version.replace("+", "<wbr>+") # Insert wrapping hint for long dev version
15+
16+
copyright = f"{date.today().year} docstub contributors."
1017

1118
templates_path = ["templates"]
1219

@@ -62,6 +69,7 @@
6269
html_sidebars = {
6370
"**": [
6471
"sidebar/brand.html",
72+
"version.html",
6573
"sidebar/search.html",
6674
"sidebar/scroll-start.html",
6775
"sidebar/navigation.html",

docs/static/furo_overrides.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@ article .align-default {
88
margin-right: unset;
99
}
1010

11+
/* Apply the same padding to the ad as other items in the sidebar */
1112
.ethical-ad-padding {
1213
padding: var(--sidebar-item-spacing-vertical) var(--sidebar-item-spacing-horizontal);
1314
}
15+
16+
/* Account for margin-bottom of a preceeding sidebar-tree's to keep spacing
17+
between items consistent. */
18+
.sidebar-tree + .sidebar-tree {
19+
margin-top: calc(var(--sidebar-tree-space-above) - var(--sidebar-item-spacing-vertical));
20+
}
21+
22+
/* Style and align inserted version in sidebar. */
23+
.sidebar-version {
24+
font-family: var(--font-stack--monospace);
25+
font-size: var(--font-size--small);
26+
color: var(--color-foreground-secondary);
27+
padding-inline: var(--sidebar-item-spacing-horizontal);
28+
padding-bottom: var(--sidebar-item-spacing-vertical) ;
29+
margin-bottom: var(--sidebar-item-spacing-vertical);
30+
overflow-wrap: break-word;
31+
}
32+
/* Remove bottom margin of brand so that version info is closer and better aligned. */
33+
.sidebar-brand-text {
34+
margin-bottom: 0;
35+
36+
}

docs/templates/ethical-ads.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{#- Indicate ad placement to Read the Docs. -#}
2+
13
<div class="sidebar-tree ethical-ad-padding">
24
<div id="ethical-ad-placement"></div>
35
</div>

docs/templates/external-links.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{#- Insert external project links into the sidebar. -#}
2+
13
<div class="sidebar-tree">
24
<p class="caption" role="heading"><span class="caption-text">Links</span></p>
35
<ul>

docs/templates/version.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{#- Insert version information into the sidebar. -#}
2+
3+
{% if version %}
4+
<div class="sidebar-version">
5+
<span>{{ version }}</span>
6+
</div>
7+
{%- endif %}

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools>=61", "setuptools_scm[toml]>=7"]
2+
requires = ["setuptools>=61", "setuptools-scm[simple]>=8"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
@@ -57,10 +57,11 @@ test = [
5757
]
5858
docs = [
5959
"sphinx",
60-
"furo",
60+
"furo ==2025.9.25",
6161
"numpydoc",
6262
"myst-parser",
6363
"sphinx-copybutton",
64+
"setuptools-scm[simple] >=8"
6465
]
6566
dev = [
6667
{include-group = "test"},

0 commit comments

Comments
 (0)