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

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


The following commit(s) were added to refs/heads/main by this push:
     new c95980f4be GH-34907: [Docs][R] Version selector reports that release 
version is dev (#35103)
c95980f4be is described below

commit c95980f4bee406504a68ff3a3d39cd86c1d97ec0
Author: Nic Crane <[email protected]>
AuthorDate: Thu Apr 27 14:53:12 2023 +0100

    GH-34907: [Docs][R] Version selector reports that release version is dev 
(#35103)
    
    This PR moves the functionality to select a different version of the docs 
from a dropdown menu (which replaces the version number span on the page) to a 
link in the footer, which links to a HTML page with clickable links to the 
different docs versions.
    
    This resolves the problem in #34907 and also fixes #14969 in which the 
JavaScript used in the dropdown interferes with the JavaScript code used for 
the search box (present since the upgrade to BS5).
    
    This change also simplifies the maintenance of the version selection 
functionality, though does remove the ability to navigate directly to the same 
reference page in a different version - overall I think this minor loss of 
functionality is a worthwhile trade for simpler maintenance.
    
    Footer before (note that the author information is already in the sidebar, 
so this is duplication):
    
![image](https://user-images.githubusercontent.com/13715823/231714608-73ec3e0b-cc28-4f41-9b22-a87033ab3977.png)
    
    Footer after:
    
![image](https://user-images.githubusercontent.com/13715823/231714402-e04b1c43-495a-477b-ae1e-4035b35b088b.png)
    
    * Closes: #34907
    
    Lead-authored-by: Nic Crane <[email protected]>
    Co-authored-by: Sutou Kouhei <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 dev/release/utils-update-docs-versions.py | 12 +++++
 r/_pkgdown.yml                            |  7 +++
 r/pkgdown/assets/versions.html            | 16 ++++++
 r/pkgdown/assets/versions.json            |  2 +-
 r/pkgdown/extra.js                        | 87 -------------------------------
 5 files changed, 36 insertions(+), 88 deletions(-)

diff --git a/dev/release/utils-update-docs-versions.py 
b/dev/release/utils-update-docs-versions.py
index 2acbe322a7..6e0137b7c8 100644
--- a/dev/release/utils-update-docs-versions.py
+++ b/dev/release/utils-update-docs-versions.py
@@ -26,6 +26,7 @@ next_version = sys.argv[3]
 
 main_versions_path = dir_path + "/docs/source/_static/versions.json"
 r_versions_path = dir_path + "/r/pkgdown/assets/versions.json"
+r_html_path = dir_path + "/r/pkgdown/assets/versions.html"
 
 split_version = version.split(".")
 split_next_version = next_version.split(".")
@@ -87,3 +88,14 @@ else:
 with open(r_versions_path, 'w') as json_file:
     json.dump(new_r_versions, json_file, indent=4)
     json_file.write("\n")
+
+# Load the updated versions JSON file
+with open(r_versions_path) as json_file:
+    data = json.load(json_file)
+
+# Write HTML to file
+with open(r_html_path, 'w') as html_file:
+    html_file.write('<!DOCTYPE html>\n<html>\n<body>')
+    for i in data:
+        html_file.write(f'<p><a 
href="../{i["version"]}r/">{i["name"]}</a></p>\n')
+    html_file.write('</body>\n</html>\n')
diff --git a/r/_pkgdown.yml b/r/_pkgdown.yml
index 45fff427d0..f3711fdc3d 100644
--- a/r/_pkgdown.yml
+++ b/r/_pkgdown.yml
@@ -281,3 +281,10 @@ repo:
     source: https://github.com/apache/arrow/blob/main/r/
     issue: https://github.com/apache/arrow/issues/
     user: https://github.com/
+
+footer:
+  structure:
+    left: older_versions
+    right: built_with
+  components:
+    older_versions: "[Older versions of these 
docs](https://arrow.apache.org/docs/r/versions.html)"
diff --git a/r/pkgdown/assets/versions.html b/r/pkgdown/assets/versions.html
new file mode 100644
index 0000000000..9c80c32735
--- /dev/null
+++ b/r/pkgdown/assets/versions.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<body><p><a href="../dev/r/">11.0.0.9000 (dev)</a></p>
+<p><a href="../r/">11.0.0 (release)</a></p>
+<p><a href="../10.0/r/">10.0.1</a></p>
+<p><a href="../9.0/r/">9.0.0</a></p>
+<p><a href="../8.0/r/">8.0.0</a></p>
+<p><a href="../7.0/r/">7.0.0</a></p>
+<p><a href="../6.0/r/">6.0.1</a></p>
+<p><a href="../5.0/r/">5.0.0</a></p>
+<p><a href="../4.0/r/">4.0.1</a></p>
+<p><a href="../3.0/r/">3.0.0</a></p>
+<p><a href="../2.0/r/">2.0.0</a></p>
+<p><a href="../1.0/r/">1.0.1</a></p>
+</body>
+</html>
diff --git a/r/pkgdown/assets/versions.json b/r/pkgdown/assets/versions.json
index 04d52dc9cb..05ae619584 100644
--- a/r/pkgdown/assets/versions.json
+++ b/r/pkgdown/assets/versions.json
@@ -4,7 +4,7 @@
         "version": "dev/"
     },
     {
-        "name": "11.0.0.3 (release)",
+        "name": "11.0.0 (release)",
         "version": ""
     },
     {
diff --git a/r/pkgdown/extra.js b/r/pkgdown/extra.js
index ec7a9b2a9f..4e67262ec1 100644
--- a/r/pkgdown/extra.js
+++ b/r/pkgdown/extra.js
@@ -15,40 +15,6 @@
 // specific language governing permissions and limitations
 // under the License.
 
-function check_page_exists_and_redirect(event) {
-
-    /**
-       * When a user uses the version dropdown in the docs, check if the page
-       * they are currently browsing exists in that version of the docs.
-       * If yes, take them there; if no, take them to the main docs page.
-       */
-
-    const path_to_try = event.target.value;
-
-    const base_path = path_to_try.match("(.*\/r\/)?")[0];
-    let tryUrl = path_to_try;
-    $.ajax({
-        type: 'HEAD',
-        url: tryUrl,
-        success: function() {
-            location.href = tryUrl;
-        }
-    }).fail(function() {
-        location.href = base_path;
-    });
-    return false;
-}
-
-/**
- * We need to do this so that the version dropdown doesn't used cached HTML
- * on Chrome on MacOS (see ARROW-15895)
- */
-$(window).bind("pageshow", function(event) {
-  if (event.originalEvent.persisted) {
-    window.location.reload()
-  }
-});
-
 (function () {
   // Load the rmarkdown tabset script
   var script = document.createElement("script");
@@ -94,59 +60,6 @@ $(window).bind("pageshow", function(event) {
       empty_ul.remove();
     });
 
-    $(document).ready(function () {
-
-      /**
-       * This replaces the package version number in the docs with a
-       * dropdown where you can select the version of the docs to view.
-       */
-
-         // Get the start of the path which includes the version number or 
"dev"
-         // where applicable and add the "/docs/" suffix
-        $pathStart = function(){
-         return window.location.origin + "/docs/";
-        }
-
-
-        // Get the end of the path after the version number or "dev" if present
-        $pathEnd  = function(){
-         var current_path = window.location.pathname;
-         // Can't do this via a positive look-behind or we lose Safari 
compatibility
-         return current_path.match("\/r.*")[0].substr(2);
-        }
-
-        // Load JSON file mapping between docs version and R package version
-        $.getJSON("https://arrow.apache.org/docs/r/versions.json";, function( 
data ) {
-          // get the current page's version number:
-                 var displayed_version = $('.version').text();
-                 // Create a dropdown selector and add the appropriate 
attributes
-          const sel = document.createElement("select");
-          sel.name = "version-selector";
-          sel.id = "version-selector";
-          sel.classList.add("navbar-default");
-          // When the selected value is changed, take the user to the version
-          // of the page they are browsing in the selected version
-          sel.onchange = check_page_exists_and_redirect;
-
-          // For each of the items in the JSON object (name/version pairs)
-                 $.each( data, function( key, val ) {
-                   // Add a new option to the dropdown selector
-            const opt = document.createElement("option");
-            // Set the path based on the 'version' field
-            opt.value = $pathStart() + val.version + "r" + $pathEnd();
-            // Set the currently selected item based on the major and minor 
version numbers
-            opt.selected = val.name.match("[0-9.]*")[0] === displayed_version;
-            // Set the displayed text based on the 'name' field
-            opt.text = val.name;
-            // Add to the selector
-            sel.append(opt);
-                   });
-
-          // Replace the HTML "version" component with the new selector
-          $("span.version").replaceWith(sel);
-        });
-    });
-
   };
 
   document.head.appendChild(script);

Reply via email to