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

gurwls223 pushed a commit to branch branch-3.5
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/branch-3.5 by this push:
     new 555c8def51e Revert "Revert "[SPARK-44742][PYTHON][DOCS] Add Spark 
version drop down to the PySpark doc site""
555c8def51e is described below

commit 555c8def51e5951c7bf5165a332795e9e330ec9d
Author: Hyukjin Kwon <gurwls...@apache.org>
AuthorDate: Tue Sep 19 10:18:18 2023 +0900

    Revert "Revert "[SPARK-44742][PYTHON][DOCS] Add Spark version drop down to 
the PySpark doc site""
    
    This reverts commit bbe12e148eb1f289cfb1f4412525f4c4381c10a9.
---
 python/docs/source/_static/css/pyspark.css         | 13 ++++
 python/docs/source/_static/versions.json           | 22 +++++++
 .../docs/source/_templates/version-switcher.html   | 77 ++++++++++++++++++++++
 python/docs/source/conf.py                         |  9 ++-
 4 files changed, 120 insertions(+), 1 deletion(-)

diff --git a/python/docs/source/_static/css/pyspark.css 
b/python/docs/source/_static/css/pyspark.css
index 89b7c65f27a..ccfe60f2bca 100644
--- a/python/docs/source/_static/css/pyspark.css
+++ b/python/docs/source/_static/css/pyspark.css
@@ -95,3 +95,16 @@ u.bd-sidebar .nav>li>ul>.active:hover>a,.bd-sidebar 
.nav>li>ul>.active>a {
 .spec_table tr, td, th {
     border-top: none!important;
 }
+
+/* Styling to the version dropdown */
+#version-button {
+  padding-left: 0.2rem;
+  padding-right: 3.2rem;
+}
+
+#version_switcher {
+  height: auto;
+  max-height: 300px;
+  width: 165px;
+  overflow-y: auto;
+}
diff --git a/python/docs/source/_static/versions.json 
b/python/docs/source/_static/versions.json
new file mode 100644
index 00000000000..3d0bd148180
--- /dev/null
+++ b/python/docs/source/_static/versions.json
@@ -0,0 +1,22 @@
+[
+    {
+        "name": "3.4.1",
+        "version": "3.4.1"
+    },
+    {
+        "name": "3.4.0",
+        "version": "3.4.0"
+    },
+    {
+        "name": "3.3.2",
+        "version": "3.3.2"
+    },
+    {
+        "name": "3.3.1",
+        "version": "3.3.1"
+    },
+    {
+        "name": "3.3.0",
+        "version": "3.3.0"
+    }
+]
diff --git a/python/docs/source/_templates/version-switcher.html 
b/python/docs/source/_templates/version-switcher.html
new file mode 100644
index 00000000000..16c443229f4
--- /dev/null
+++ b/python/docs/source/_templates/version-switcher.html
@@ -0,0 +1,77 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<div id="version-button" class="dropdown">
+    <button type="button" class="btn btn-secondary btn-sm navbar-btn 
dropdown-toggle" id="version_switcher_button" data-toggle="dropdown">
+        {{ release }}
+        <span class="caret"></span>
+    </button>
+    <div id="version_switcher" class="dropdown-menu list-group-flush py-0" 
aria-labelledby="version_switcher_button">
+    <!-- dropdown will be populated by javascript on page load -->
+    </div>
+</div>
+
+<script type="text/javascript">
+// Function to construct the target URL from the JSON components
+function buildURL(entry) {
+    var template = "{{ switcher_template_url }}";  // supplied by jinja
+    template = template.replace("{version}", entry.version);
+    return template;
+}
+
+// Function to check if corresponding page path exists in other version of docs
+// and, if so, go there instead of the homepage of the other docs version
+function checkPageExistsAndRedirect(event) {
+    const currentFilePath = "{{ pagename }}.html",
+          otherDocsHomepage = event.target.getAttribute("href");
+    let tryUrl = `${otherDocsHomepage}${currentFilePath}`;
+    $.ajax({
+        type: 'HEAD',
+        url: tryUrl,
+        // if the page exists, go there
+        success: function() {
+            location.href = tryUrl;
+        }
+    }).fail(function() {
+        location.href = otherDocsHomepage;
+    });
+    return false;
+}
+
+// Function to populate the version switcher
+(function () {
+    // get JSON config
+    $.getJSON("{{ switcher_json_url }}", function(data, textStatus, jqXHR) {
+        // create the nodes first (before AJAX calls) to ensure the order is
+        // correct (for now, links will go to doc version homepage)
+        $.each(data, function(index, entry) {
+            // if no custom name specified (e.g., "latest"), use version string
+            if (!("name" in entry)) {
+                entry.name = entry.version;
+            }
+            // construct the appropriate URL, and add it to the dropdown
+            entry.url = buildURL(entry);
+            const node = document.createElement("a");
+            node.setAttribute("class", "list-group-item list-group-item-action 
py-1");
+            node.setAttribute("href", `${entry.url}`);
+            node.textContent = `${entry.name}`;
+            node.onclick = checkPageExistsAndRedirect;
+            $("#version_switcher").append(node);
+        });
+    });
+})();
+</script>
diff --git a/python/docs/source/conf.py b/python/docs/source/conf.py
index 38c331048e7..0f57cb37cee 100644
--- a/python/docs/source/conf.py
+++ b/python/docs/source/conf.py
@@ -177,10 +177,17 @@ autosummary_generate = True
 # a list of builtin themes.
 html_theme = 'pydata_sphinx_theme'
 
+html_context = {
+    "switcher_json_url": "_static/versions.json",
+    "switcher_template_url": 
"https://spark.apache.org/docs/{version}/api/python/index.html";,
+}
+
 # Theme options are theme-specific and customize the look and feel of a theme
 # further.  For a list of options available for each theme, see the
 # documentation.
-#html_theme_options = {}
+html_theme_options = {
+    "navbar_end": ["version-switcher"]
+}
 
 # Add any paths that contain custom themes here, relative to this directory.
 #html_theme_path = []


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to