diff --git a/ci/scripts/website_build.sh b/ci/scripts/website_build.sh index b80338d813..480c57c908 100755 --- a/ci/scripts/website_build.sh +++ b/ci/scripts/website_build.sh @@ -60,19 +60,18 @@ main() { # Copy the version script and regenerate the version list # The versions get embedded into the JavaScript file to save a roundtrip rm -f "${site}/version.js" - cp "${repo}/docs/source/_static/version.js" "${site}/version.js" - echo >> "${site}/version.js" echo 'const versions = `' >> "${site}/version.js" pushd "${site}" + rm -f "${site}/versions.txt" for inv in */objects.inv; do + if [[ "$(dirname $inv)" = "current" ]]; then + continue + fi echo "$(dirname $inv);$(sphobjinv convert json $inv - | jq -r .version)" done | sort -t ";" --version-sort | tee --append "${site}/version.js" "${site}/versions.txt" popd - echo '`;' >> "${site}/version.js" - git -C "${site}" add -f "version.js" - # Determine the latest stable version local -r latest_docs=$(grep -E ';[0-9]+\.[0-9]+\.[0-9]+$' "${site}/versions.txt" | sort -t ';' --version-sort | tail -n1) if [[ -z "${latest_docs}" ]]; then @@ -85,10 +84,21 @@ main() { fi echo "Latest version: ${latest_version} in directory ${latest_dir}" + # Make a copy of the latest release under a stable URL + rm -rf "${site}/current/" + cp -r "${site}/${latest_dir}" "${site}/current/" + git -C "${site}" add -f "current" + + echo "current;${latest_version} (current)" >> "${site}/version.js" + + echo '`;' >> "${site}/version.js" + cat "${repo}/docs/source/_static/version.js" >> "${site}/version.js" + git -C "${site}" add -f "version.js" + # Generate index.html cat > "${site}/index.html" << EOF - + EOF git -C "${site}" add -f "index.html" @@ -96,7 +106,7 @@ EOF mkdir -p "${site}/latest" cat > "${site}/latest/index.html" << EOF - + EOF git -C "${site}" add -f "latest/index.html" } diff --git a/docs/source/_static/version.js b/docs/source/_static/version.js index 51ade786be..88efda5073 100644 --- a/docs/source/_static/version.js +++ b/docs/source/_static/version.js @@ -21,7 +21,7 @@ // update the script globally. It depends on certain variables being // injected into the Sphinx template. -window.addEventListener("DOMContentLoaded", () => { +function adbcInjectVersionSwitcher() { // The template should contain this list, we just populate it const root = document.querySelector("#version-switcher ul"); @@ -29,10 +29,13 @@ window.addEventListener("DOMContentLoaded", () => { // Format: // path;version\npath2;version2;\n... // Versions are sorted at generation time + versions .trim() .split(/\n/g) .map((version) => version.split(/;/)) + // Most recent on top + .reverse() .forEach((version) => { const el = document.createElement("a"); // Variable injected by template @@ -48,7 +51,11 @@ window.addEventListener("DOMContentLoaded", () => { el.addEventListener("click", (e) => { e.preventDefault(); try { - const relativePart = window.location.pathname.replace(/^\/[^\/]+\//, ""); + let relativePart = window.location.pathname.replace(/^\//, ""); + // Remove the adbc/ prefix + relativePart = relativePart.replace(/^adbc[^\/]+\//, ""); + // Remove the version number + relativePart = relativePart.replace(/^[^\/]+\//, ""); const newUrl = `${el.getAttribute("href")}/${relativePart}`; window.fetch(newUrl).then((resp) => { if (resp.status === 200) { @@ -65,4 +72,10 @@ window.addEventListener("DOMContentLoaded", () => { return false; }); }); -}); +}; + +if (document.readyState !== "loading") { + adbcInjectVersionSwitcher(); +} else { + window.addEventListener("DOMContentLoaded", adbcInjectVersionSwitcher); +}