diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index e7501bc..25c1332 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -4,7 +4,6 @@ on: push: branches: - devel-2.0 - - master workflow_dispatch: permissions: @@ -20,17 +19,25 @@ jobs: build: name: Build documentation runs-on: ubuntu-latest + env: + BLEND_DOC_VERSIONS: '[["devel-2.0","https://bioye97.github.io/blend/"],["2.0.0","https://bioye97.github.io/blend/2.0.0/"]]' steps: - - name: Checkout + - name: Checkout BLEND development source uses: actions/checkout@v6 + with: + ref: devel-2.0 + + - name: Checkout BLEND 2.0.0 source + uses: actions/checkout@v6 + with: + repository: Bioye97/blend + ref: v2.0.0 + path: _versions/blend-2.0.0 - - name: Define documentation versions + - name: Add version selector support to BLEND 2.0.0 run: | - { - echo 'BLEND_DOC_VERSIONS<> "${GITHUB_ENV}" + cp doc/rst/source/conf.py _versions/blend-2.0.0/doc/rst/source/conf.py + cp doc/rst/source/_static/blend.js _versions/blend-2.0.0/doc/rst/source/_static/blend.js - name: Set up Python uses: actions/setup-python@v6 @@ -67,7 +74,7 @@ jobs: - name: Configure 2.0.0 documentation run: | - cmake -S . -B build-2.0.0 \ + cmake -S _versions/blend-2.0.0 -B build-2.0.0 \ -DBLEND_BUILD_DOCS=ON \ -DBLEND_BUILD_EXAMPLES=OFF \ -DBLEND_BUILD_TESTS=OFF \ diff --git a/doc/rst/source/_static/blend.js b/doc/rst/source/_static/blend.js index 8161f70..a483638 100644 --- a/doc/rst/source/_static/blend.js +++ b/doc/rst/source/_static/blend.js @@ -7,9 +7,36 @@ for (i = 0; i < selects.length; i++) { selects[i].addEventListener("change", function () { - if (this.value) { - window.location.href = this.value; + var base; + var candidate; + var currentBase = null; + var j; + var relativePath; + var target; + + if (!this.value) { + return; + } + + for (j = 0; j < this.options.length; j++) { + candidate = new URL(this.options[j].value, window.location.href); + if (candidate.origin === window.location.origin && + window.location.pathname.indexOf(candidate.pathname) === 0 && + (!currentBase || candidate.pathname.length > currentBase.pathname.length)) { + currentBase = candidate; + } } + + target = new URL(this.value, window.location.href); + if (currentBase) { + base = currentBase.pathname; + relativePath = window.location.pathname.substring(base.length); + target = new URL(relativePath, target); + target.search = window.location.search; + target.hash = window.location.hash; + } + + window.location.href = target.href; }); } });