Skip to content

Commit 4bb3a7b

Browse files
Merge pull request #613 from laughingman7743/version-selector-implementation
docs: Implement version selector with sphinx-multiversion
2 parents 0ddcd52 + c09dbfe commit 4bb3a7b

8 files changed

Lines changed: 66 additions & 58 deletions

File tree

.github/workflows/docs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
workflow_dispatch:
55
push:
66
branches: ['master']
7+
tags: ['v*']
78

89
permissions:
910
contents: read
@@ -32,7 +33,6 @@ jobs:
3233
enable-cache: true
3334
- run: |
3435
uv sync --group dev
35-
uv build
3636
make docs
3737
- name: Upload artifact
3838
uses: actions/upload-pages-artifact@v3

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ tox:
2727

2828
.PHONY: docs
2929
docs:
30-
cd ./docs && uv run $(MAKE) clean html
30+
uv build
31+
uv run sphinx-multiversion docs docs/_build/html
32+
echo '<meta http-equiv="refresh" content="0; url=./master/index.html">' > docs/_build/html/index.html
33+
touch docs/_build/html/.nojekyll
3134

3235
.PHONY: tool
3336
tool:

docs/Makefile

Lines changed: 0 additions & 20 deletions
This file was deleted.

docs/_templates/versioning.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% if versions %}
2+
<div class="sidebar-tree">
3+
<p class="caption" role="heading" aria-level="2"><span class="caption-text">VERSIONS:</span></p>
4+
<div class="version-dropdown" style="margin-bottom: 1rem;">
5+
<select onchange="window.location.href = this.value" style="width: 100%; padding: 0.5rem; border: 1px solid var(--color-background-border); border-radius: 0.25rem; background-color: var(--color-background-secondary); color: var(--color-foreground-primary); font-size: var(--font-size--small); cursor: pointer;">
6+
{% for item in versions %}
7+
<option value="{{ item.url }}" {% if item.name == current_version %}selected{% endif %}>
8+
{{ item.name }}{% if item.name == current_version %} (current){% endif %}
9+
</option>
10+
{% endfor %}
11+
</select>
12+
</div>
13+
</div>
14+
{% endif %}

docs/conf.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ def get_version():
3434

3535
extensions = [
3636
"sphinx.ext.autodoc",
37-
"sphinx.ext.autosummary",
37+
"sphinx.ext.autosummary",
3838
"sphinx.ext.viewcode",
3939
"sphinx.ext.napoleon",
4040
"sphinx.ext.intersphinx",
4141
"sphinx.ext.githubpages",
42+
"sphinx_multiversion",
4243
]
4344

4445
# Napoleon settings for Google-style docstrings
@@ -96,3 +97,32 @@ def get_version():
9697
"source_branch": "master",
9798
"source_directory": "docs/",
9899
}
100+
101+
# Sidebar templates
102+
html_sidebars = {
103+
"**": [
104+
"sidebar/brand.html",
105+
"sidebar/search.html",
106+
"sidebar/scroll-start.html",
107+
"sidebar/navigation.html",
108+
"versioning.html",
109+
"sidebar/scroll-end.html",
110+
]
111+
}
112+
113+
# -- Sphinx-multiversion configuration ----------------------------------------
114+
115+
# Whitelist pattern for tags (semantic versioning: vX.Y.Z)
116+
smv_tag_whitelist = r"^v\d+\.\d+\.\d+$" # Match vX.Y.Z tags
117+
118+
# Whitelist pattern for branches
119+
smv_branch_whitelist = r"^master$" # Only build master branch
120+
121+
# Whitelist pattern for remotes
122+
smv_remote_whitelist = r"^origin$" # Only build from origin remote
123+
124+
# Output all versions to the root directory
125+
smv_outputdir_format = "{ref.name}"
126+
127+
# Specify the latest version (used for stable redirect)
128+
smv_latest_version = "master"

docs/make.bat

Lines changed: 0 additions & 35 deletions
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ dev = [
5959
"pytest-xdist",
6060
"pytest-dependency",
6161
"sphinx",
62+
"sphinx-multiversion",
6263
"furo",
6364
"types-python-dateutil",
6465
]

uv.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)