diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 87f16e2..743c2d1 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -18,7 +18,18 @@ jobs: - name: Download theme run: doc/download-theme.sh - uses: mattnotmitt/doxygen-action@edge - - name: Deploy + + - name: Deploy version switcher + uses: peaceiris/actions-gh-pages@v3 + if: github.ref == 'refs/heads/main' + with: + deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} + external_repository: upa-url/docs + destination_dir: docs/common + publish_branch: main + publish_dir: ./doc/common + + - name: Deploy documentation uses: peaceiris/actions-gh-pages@v3 if: github.ref == 'refs/heads/main' with: diff --git a/doc/common/version-select.css b/doc/common/version-select.css new file mode 100644 index 0000000..05107fe --- /dev/null +++ b/doc/common/version-select.css @@ -0,0 +1,12 @@ +#version-td { + padding: 0 0 0 0.5em; +} + +#version-select { + background-color: transparent; + border: none; + font-family: inherit; + font-size: inherit; + cursor: pointer; + line-height: inherit; +} diff --git a/doc/common/version-select.js b/doc/common/version-select.js new file mode 100644 index 0000000..eb87346 --- /dev/null +++ b/doc/common/version-select.js @@ -0,0 +1,59 @@ +// Copyright 2023 Rimas Misevičius +// Distributed under the BSD-style license that can be +// found in the LICENSE file. + +(function () { + // path segment to replace with version string + const path_segment_ind = 2; + // versions.txt is in the same folder as this script + const versions_url = new URL("versions.txt", document.currentScript.src); + + window.addEventListener("DOMContentLoaded", event => { + const list_ctl = document.getElementById("version-select"); + + function on_change() { + const path_segments = window.location.pathname.split('/'); + path_segments[path_segment_ind] = list_ctl.value; + list_ctl.value = initial_dir; // return version of this document + // ... and load document of other version + window.location.pathname = path_segments.join('/'); + } + + // Initial version + const initial_dir = window.location.pathname.split('/')[path_segment_ind]; + const initial_option = list_ctl.options[0]; + initial_option.selected = true; + initial_option.value = initial_dir; + // Change event + list_ctl.addEventListener("change", on_change); + + // Fetch versions and populate versions list + fetch(versions_url) + .then(response => response.text()) + .then(text => { + // Split text into lines and remove blank lines if present + const versions = text + .split(/\r?\n/gm) + .map(line => line.trim()) + .filter(line => line.length > 0) + .map(line => line.split(":")); + // Populate versions list + let append = false; + versions.forEach(dir_ver => { + const dir = dir_ver[0]; + const ver = dir_ver[dir_ver.length - 1]; + if (dir === initial_dir) { + append = true; + } else { + const option = document.createElement('option'); + option.text = ver; + option.value = dir; + if (append) + list_ctl.appendChild(option); + else + list_ctl.insertBefore(option, initial_option) + } + }); + }); + }); +})(); diff --git a/doc/common/versions.txt b/doc/common/versions.txt new file mode 100644 index 0000000..ba2906d --- /dev/null +++ b/doc/common/versions.txt @@ -0,0 +1 @@ +main diff --git a/doc/header.html b/doc/header.html index 666e6ec..95e3672 100644 --- a/doc/header.html +++ b/doc/header.html @@ -23,6 +23,7 @@ + $extrastylesheet +
@@ -50,10 +52,15 @@