Skip to content

Commit

Permalink
Trying the good old version switcher again.
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz00 committed Jan 13, 2025
1 parent 2908bd2 commit 131f2ee
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
57 changes: 53 additions & 4 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ on:
push:
branches:
- 'main'
paths:
- 'docs/**'
- 'src/**'
- 'develop'
tags:
- 'v*.*'

workflow_dispatch:

permissions:
Expand Down Expand Up @@ -36,10 +37,58 @@ jobs:
- name: Install dependencies
run: make install-docs

- name: Determine Documentation Context
id: version
run: |
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
echo "VERSION=latest" >> $GITHUB_ENV
elif [ "${{ github.ref }}" == "refs/heads/develop" ]; then
echo "VERSION=develop" >> $GITHUB_ENV
elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then
echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
else
echo "Unknown branch or tag" && exit 1
fi
- name: Generate switcher.json
run: |
cat <<EOF > generate_switcher.py
import json
import subprocess
tags_output = subprocess.run(
["git", "tag", "-l", "v*.*"], capture_output=True, text=True
).stdout.strip()
tags = tags_output.split("\n") if tags_output else []
versions = [
{"version": "latest", "url": "https://patcher.liquidzoo.io/latest/"},
{"version": "develop", "url": "https://patcher.liquidzoo.io/develop/"},
]
for tag in tags:
if tag:
versions.append({"version": tag, "url": f"https://patcher.liquidzoo.io/{tag}/"})
with open("docs/_build/_static/switcher.json", "w") as f:
json_data = json.dump(versions, f, indent=4)
EOF
python3 generate_switcher.py
rm generate_switcher.py
- name: Copy CNAME to build
run: |
cp CNAME docs/_build/${{ env.VERSION }}
- name: Build Sphinx Docs
env:
PYTHONPATH: ${{ github.workspace }}
run: make docs
run: make docs-version VERSION=${{ env.VERSION }}

- name: Ensure switcher is deployed
run: |
cp docs/_build/_static/switcher.json docs/_build/
- name: Upload Artifact
uses: actions/upload-pages-artifact@v3
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,11 @@ build:
python3 -m build --sdist --wheel

docs:
sphinx-build -b html docs/ docs/_build/
@echo "Building Sphinx Docs for version $(VERSION)..."
sphinx-build -b html docs/ docs/_build/$(VERSION)

docs-latest:
$(MAKE) docs VERSION=latest

docs-version:
$(MAKE) docs VERSION=$(VERSION)
6 changes: 5 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@
"navbar_align": "left",
"announcement": "https://raw.githubusercontent.com/liquidz00/Patcher/main/docs/_templates/custom-template.html",
"show_prev_next": False,
"navbar_start": ["navbar-logo"],
"navbar_start": ["navbar-logo", "version-switcher"],
"switcher": {
"json_url": "https://patcher.liquidzoo.io/_static/switcher.json",
"version_match": version,
},
"navbar_center": ["navbar-nav"],
"navbar_end": ["theme-switcher", "navbar-icon-links"],
"icon_links": [
Expand Down

0 comments on commit 131f2ee

Please sign in to comment.