diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index c410b2e69..8c8ca2274 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -199,25 +199,41 @@ jobs: git clone --depth=1 git@github.com:amaranth-lang/amaranth-lang.github.io.git ~/amaranth-lang.github.io cd ~/amaranth-lang.github.io/docs/amaranth/ - ( - venv_path=$(mktemp -d) + venv_path=~/.generate-versions-json-venv python3 -m venv "$venv_path" source "$venv_path"/bin/activate pip install packaging - python >versions.json < 0: + with open("versions.json", "w") as f: + json.dump(versions, f, indent=2) + else: + Path("versions.json").unlink() EOF - ) - git add versions.json + [[ -f versions.json ]] && git add versions.json || git rm versions.json || true if ! git diff-index --quiet --cached HEAD; then git \ -c user.name="$GITHUB_ACTOR" \ diff --git a/docs/_static/version-switch.js b/docs/_static/version-switch.js index a71319314..f85c07837 100644 --- a/docs/_static/version-switch.js +++ b/docs/_static/version-switch.js @@ -5,6 +5,11 @@ document.addEventListener('DOMContentLoaded', () => { ); function insertVersionSwitch(versions) { + let currentVersion = DOCUMENTATION_OPTIONS.VERSION; + if (!versions.some(({ name }) => name === currentVersion)) { + return; + } + let versionElement = document.querySelector('.wy-side-nav-search > .version'); if (!versionElement) return; @@ -72,14 +77,6 @@ document.addEventListener('DOMContentLoaded', () => { `); document.adoptedStyleSheets.push(cssStyleSheet); - let currentVersion = DOCUMENTATION_OPTIONS.VERSION; - if (!versions.some(({ name }) => name === currentVersion)) { - versions = [ - { name: currentVersion, root_url: contentRoot }, - ...versions, - ]; - } - for (let { name, root_url: rootURL } of versions) { rootURL = new URL(rootURL, window.location.href);