Skip to content

Commit c4d7fb7

Browse files
committed
Enhance documentation build process and add version switcher for improved navigation
1 parent d0b4bf5 commit c4d7fb7

4 files changed

Lines changed: 58 additions & 9 deletions

File tree

.github/workflows/docs.yml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ jobs:
4545
- name: Install dependencies (with docs extras)
4646
run: uv sync --extra docs
4747

48-
# ── Sphinx build ───────────────────────────────────────────────────────
49-
# -W turns warnings into errors so broken cross-references are caught.
50-
# Remove -W if the gallery examples produce unavoidable warnings.
51-
- name: Build HTML documentation
52-
run: |
53-
uv run sphinx-build -b html docs build/html -W --keep-going
54-
5548
# ── Determine deployment target ─────────────────────────────────────────
5649
# Release tag (refs/tags/v1.2.3) → destination = "v1.2.3"
5750
# Everything else (push to main, manual dispatch) → destination = "dev"
@@ -65,6 +58,15 @@ jobs:
6558
echo "dest_dir=dev" >> "$GITHUB_OUTPUT"
6659
fi
6760
61+
# ── Sphinx build ───────────────────────────────────────────────────────
62+
# -W turns warnings into errors so broken cross-references are caught.
63+
# Remove -W if the gallery examples produce unavoidable warnings.
64+
- name: Build HTML documentation
65+
env:
66+
DOCS_VERSION: ${{ steps.target.outputs.dest_dir }}
67+
run: |
68+
uv run sphinx-build -b html docs build/html -W --keep-going
69+
6870
# ── Deploy to gh-pages ────────────────────────────────────────────────
6971
# keep_files: true preserves all existing directories on the branch so
7072
# versioned releases accumulate rather than overwriting each other.
@@ -80,3 +82,16 @@ jobs:
8082
commit_message: |
8183
docs: deploy ${{ steps.target.outputs.dest_dir }} @ ${{ github.sha }}
8284
85+
# ── Deploy root files (redirect + switcher) ────────────────────────────
86+
# Places index.html and switcher.json at the root of gh-pages so the
87+
# bare URL redirects to dev/ and the version switcher is always reachable.
88+
- name: Deploy root redirect and switcher
89+
uses: peaceiris/actions-gh-pages@v4
90+
with:
91+
github_token: ${{ secrets.GITHUB_TOKEN }}
92+
publish_dir: ./docs/_root
93+
destination_dir: .
94+
keep_files: true
95+
commit_message: |
96+
docs: update root redirect and switcher.json @ ${{ github.sha }}
97+

docs/_root/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>anyplotlib – redirecting…</title>
6+
<!-- Redirect to the latest dev docs. -->
7+
<meta http-equiv="refresh" content="0; url=dev/" />
8+
<link rel="canonical" href="dev/" />
9+
</head>
10+
<body>
11+
<p>
12+
Redirecting to <a href="dev/">dev documentation</a>
13+
</p>
14+
</body>
15+
</html>
16+

docs/_root/switcher.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"name": "dev (latest)",
4+
"version": "dev",
5+
"url": "https://cssfrancis.github.io/anyplotlib/dev/"
6+
},
7+
]
8+

docs/conf.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
author = "anyplotlib contributors"
2020
release = "0.1.0"
2121

22+
# When built in CI the workflow sets DOCS_VERSION to the tag name (e.g.
23+
# "v0.1.0") or "dev". Fall back to "dev" for local builds.
24+
_docs_version = os.environ.get("DOCS_VERSION", "dev")
25+
_base = "https://cssfrancis.github.io/anyplotlib/"
26+
html_baseurl = f"{_base}{_docs_version}/"
27+
2228
# -- General configuration ---------------------------------------------------
2329
extensions = [
2430
"sphinx.ext.autodoc",
@@ -76,13 +82,17 @@
7682
html_static_path = ["_static"]
7783

7884
html_theme_options = {
79-
"github_url": "https://github.com/",
85+
"github_url": "https://github.com/CSSFrancis/anyplotlib",
8086
"logo": {
8187
"image_light": "_static/anyplotlib.svg",
8288
"image_dark": "_static/anyplotlib.svg",
8389
"text": "anyplotlib",
8490
},
85-
"navbar_end": ["navbar-icon-links"],
91+
"switcher": {
92+
"json_url": f"{_base}switcher.json",
93+
"version_match": _docs_version,
94+
},
95+
"navbar_end": ["version-switcher", "navbar-icon-links"],
8696
"show_toc_level": 2,
8797
}
8898

0 commit comments

Comments
 (0)