This is an automated email from the ASF dual-hosted git repository.

lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git


The following commit(s) were added to refs/heads/main by this push:
     new 2530e465 docs: add 'current' alias for latest released version (#979)
2530e465 is described below

commit 2530e46565e805a5fe5f191324d9328c66928e43
Author: David Li <[email protected]>
AuthorDate: Wed Aug 16 09:02:57 2023 -0400

    docs: add 'current' alias for latest released version (#979)
    
    Fixes #959.
    Fixes #978.
    
    ---------
    
    Co-authored-by: Sutou Kouhei <[email protected]>
---
 ci/scripts/website_build.sh    | 24 +++++++++++++++++-------
 docs/source/_static/version.js | 19 ++++++++++++++++---
 2 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/ci/scripts/website_build.sh b/ci/scripts/website_build.sh
index b80338d8..480c57c9 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
 <!DOCTYPE html>
-<meta http-equiv="Refresh" content="0; url=$latest_dir/index.html">
+<meta http-equiv="Refresh" content="0; url=current/index.html">
 EOF
     git -C "${site}" add -f "index.html"
 
@@ -96,7 +106,7 @@ EOF
     mkdir -p "${site}/latest"
     cat > "${site}/latest/index.html" << EOF
 <!DOCTYPE html>
-<meta http-equiv="Refresh" content="0; url=../$latest_dir/index.html">
+<meta http-equiv="Refresh" content="0; url=../current/index.html">
 EOF
     git -C "${site}" add -f "latest/index.html"
 }
diff --git a/docs/source/_static/version.js b/docs/source/_static/version.js
index 51ade786..88efda50 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);
+}

Reply via email to