You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ka...@apache.org on 2019/11/08 17:26:50 UTC

[airflow-site] branch aip-11 updated: Add version selector (#143)

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

kamilbregula pushed a commit to branch aip-11
in repository https://gitbox.apache.org/repos/asf/airflow-site.git


The following commit(s) were added to refs/heads/aip-11 by this push:
     new faad101  Add version selector (#143)
faad101 is described below

commit faad101b593adab46556d031169ca9d91df7f667
Author: Kamil BreguĊ‚a <mi...@users.noreply.github.com>
AuthorDate: Fri Nov 8 18:26:44 2019 +0100

    Add version selector (#143)
---
 Dockerfile                                         |  3 ++
 .../show_docs_index_json.sh                        | 24 ++++------
 landing-pages/.gitignore                           |  2 +-
 landing-pages/create-index.js                      |  2 +-
 .../assets/scss/_dropdown.scss}                    | 24 +++++++---
 landing-pages/site/assets/scss/main-custom.scss    |  1 +
 .../site/layouts/partials}/version-selector.html   | 24 +++++-----
 landing-pages/site/static/{ => _gen}/indexes/.keep |  0
 landing-pages/src/docs-index.js                    |  1 +
 landing-pages/src/index.js                         |  1 +
 landing-pages/src/js/searchBlogPosts.js            |  4 +-
 landing-pages/src/js/versionSelector.js            | 56 ++++++++++++++++++++++
 site.sh                                            |  6 +++
 sphinx_airflow_theme/demo/conf.py                  |  3 +-
 .../sphinx_airflow_theme/__init__.py               |  1 -
 .../sphinx_airflow_theme/version-selector.html     | 20 ++++----
 16 files changed, 121 insertions(+), 51 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 585cbc7..d338ebc 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -54,6 +54,9 @@ RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
     && apt-get clean \
     && rm -rf /var/lib/apt/lists/*
 
+RUN curl -sL "https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64" > /usr/local/bin/jq \
+    && chmod +x /usr/local/bin/jq
+
 RUN HUGOHOME="$(mktemp -d)" \
     && export HUGOHOME \
     && curl -sL https://github.com/gohugoio/hugo/releases/download/v0.58.3/hugo_extended_0.58.3_Linux-64bit.tar.gz > "${HUGOHOME}/hugo.tar.gz" \
diff --git a/sphinx_airflow_theme/sphinx_airflow_theme/__init__.py b/docs-archive/show_docs_index_json.sh
old mode 100644
new mode 100755
similarity index 60%
copy from sphinx_airflow_theme/sphinx_airflow_theme/__init__.py
copy to docs-archive/show_docs_index_json.sh
index 7165840..297d737
--- a/sphinx_airflow_theme/sphinx_airflow_theme/__init__.py
+++ b/docs-archive/show_docs_index_json.sh
@@ -1,3 +1,5 @@
+#!/usr/bin/env bash
+
 # 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
@@ -15,20 +17,14 @@
 # specific language governing permissions and limitations
 # under the License.
 
-from os import path
-
-__version__ = '0.0.1'
-__version_full__ = __version__
-
+set -euo pipefail
 
-def get_html_theme_path():
-    """Return list of HTML theme paths."""
-    cur_dir = path.abspath(path.dirname(path.dirname(__file__)))
-    return cur_dir
+MY_DIR="$(cd "$(dirname "$0")" && pwd)"
+pushd "${MY_DIR}" &>/dev/null || exit 1
 
+jq -n '{stable: $stable, versions: $versions[0:-1] | split("\n") }' \
+    -M \
+    --rawfile stable <(cat stable.txt | tr -d '[:space:]') \
+    --rawfile versions <(ls -d ./*/ | cut -d "/" -f 2)
 
-# See http://www.sphinx-doc.org/en/stable/theming.html#distribute-your-theme-as-a-python-package
-def setup(app):
-    app.add_html_theme('sphinx_airflow_theme', path.abspath(path.dirname(__file__)))
-    app.add_stylesheet('_gen/css//main-custom.min.css')
-    app.add_js_file('_gen/js/docs.js')
+popd &>/dev/null || exit 1
diff --git a/landing-pages/.gitignore b/landing-pages/.gitignore
index c8b191f..4aa6c9e 100644
--- a/landing-pages/.gitignore
+++ b/landing-pages/.gitignore
@@ -2,4 +2,4 @@ node_modules/
 dist/
 site/data/webpack.json
 resources/
-site/static/indexes/
+site/static/_gen/
diff --git a/landing-pages/create-index.js b/landing-pages/create-index.js
index 69ec28f..495b5fc 100644
--- a/landing-pages/create-index.js
+++ b/landing-pages/create-index.js
@@ -27,7 +27,7 @@ const parse = promisify(frontMatterParser.parse.bind(frontMatterParser));
 const lunrjs = require("lunr");
 
 const contentDirectory = `${__dirname}/site/content`;
-const outputtDirectory = `${__dirname}/site/static/indexes`;
+const outputtDirectory = `${__dirname}/site/static/_gen/indexes`;
 
 
 async function isDirectoryExists(dirPath) {
diff --git a/landing-pages/src/docs-index.js b/landing-pages/site/assets/scss/_dropdown.scss
similarity index 75%
copy from landing-pages/src/docs-index.js
copy to landing-pages/site/assets/scss/_dropdown.scss
index 884ea65..888d67c 100644
--- a/landing-pages/src/docs-index.js
+++ b/landing-pages/site/assets/scss/_dropdown.scss
@@ -16,11 +16,21 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+@import "fonts";
+@import "colors";
 
-import "./js/navbarScroll";
-import "./js/drawer";
-import "./js/contentDrawer";
-import "./js/progressTracking";
-import "./js/rating";
-import "./js/makeTableResponsive";
-import "./js/tocTree";
+.dropdown-menu {
+  font-family: $primary-font;
+}
+
+.dropdown-toggle::after {
+  color: map-get($colors, greyish-brown);
+}
+
+.sidebar__version-selector {
+  margin-bottom: 22px;
+
+  a {
+    @extend .bodytext__medium--brownish-grey;
+  }
+}
diff --git a/landing-pages/site/assets/scss/main-custom.scss b/landing-pages/site/assets/scss/main-custom.scss
index 8a1ed45..7b06c2a 100644
--- a/landing-pages/site/assets/scss/main-custom.scss
+++ b/landing-pages/site/assets/scss/main-custom.scss
@@ -49,3 +49,4 @@
 @import "rst-content";
 @import "pygments";
 @import "content-drawer";
+@import "dropdown";
diff --git a/sphinx_airflow_theme/sphinx_airflow_theme/version-selector.html b/landing-pages/site/layouts/partials/version-selector.html
similarity index 55%
copy from sphinx_airflow_theme/sphinx_airflow_theme/version-selector.html
copy to landing-pages/site/layouts/partials/version-selector.html
index d5e400a..63db3e9 100644
--- a/sphinx_airflow_theme/sphinx_airflow_theme/version-selector.html
+++ b/landing-pages/site/layouts/partials/version-selector.html
@@ -1,4 +1,4 @@
-{#
+{{/*
  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
@@ -15,19 +15,17 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
-#}
+*/}}
 
-<div id="version-selector" class="sidebar__version-selector">
-    <a class="dropdown-toggle" href="#" id="versionDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
-        <span class="bodytext__medium--greyish-brown">Version: </span><span id="selected-version">undefined</span>
+<div id="docs-version-selector" class="docs-version-selector sidebar__version-selector">
+    <a class="dropdown-toggle" href="#" id="versionDropdown" role="button" data-toggle="dropdown" aria-haspopup="true"
+       aria-expanded="false">
+        <span class="bodytext__medium--greyish-brown">Version: </span><span class="version">Select version</span>
     </a>
-    <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(15px, 33px, 0px);">
-        <a class="dropdown-item" href="/docs/1.10.1">1.10.1</a>
-        <a class="dropdown-item" href="/docs/1.10.2">1.10.2</a>
-        <a class="dropdown-item" href="/docs/1.10.3">1.10.3</a>
-        <a class="dropdown-item" href="/docs/1.10.4">1.10.4</a>
-        <a class="dropdown-item" href="/docs/1.10.5">1.10.5</a>
-        <a class="dropdown-item" href="/docs/1.10.6">1.10.6</a>
-        <a class="dropdown-item" href="/docs/1.10.7">1.10.7</a>
+    <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
+
     </div>
+    <script type="application/x-template" id="version-item-template">
+        <a class="dropdown-item"></a>
+    </script>
 </div>
diff --git a/landing-pages/site/static/indexes/.keep b/landing-pages/site/static/_gen/indexes/.keep
similarity index 100%
rename from landing-pages/site/static/indexes/.keep
rename to landing-pages/site/static/_gen/indexes/.keep
diff --git a/landing-pages/src/docs-index.js b/landing-pages/src/docs-index.js
index 884ea65..7c0917e 100644
--- a/landing-pages/src/docs-index.js
+++ b/landing-pages/src/docs-index.js
@@ -24,3 +24,4 @@ import "./js/progressTracking";
 import "./js/rating";
 import "./js/makeTableResponsive";
 import "./js/tocTree";
+import "./js/versionSelector";
diff --git a/landing-pages/src/index.js b/landing-pages/src/index.js
index 9a871e7..2ebe023 100644
--- a/landing-pages/src/index.js
+++ b/landing-pages/src/index.js
@@ -25,6 +25,7 @@ import "./js/contentDrawer";
 import "./js/progressTracking";
 import "./js/rating";
 import "./js/makeTableResponsive";
+import "./js/versionSelector";
 
 if (document.querySelector("#search")) {
     import(/* webpackChunkName: "search" */ "./js/searchBlogPosts");
diff --git a/landing-pages/src/js/searchBlogPosts.js b/landing-pages/src/js/searchBlogPosts.js
index 85fe443..5cd516e 100644
--- a/landing-pages/src/js/searchBlogPosts.js
+++ b/landing-pages/src/js/searchBlogPosts.js
@@ -47,8 +47,8 @@ const setTags = (tagsContainer, tags) => {
 };
 
 Promise.all([
-  fetch("/indexes/en/blog-index.json"),
-  fetch("/indexes/en/blog-posts.json")
+  fetch("/_gen/indexes/en/blog-index.json"),
+  fetch("/_gen/indexes/en/blog-posts.json")
 ]).then(function([indexResp, postsResp]) {
   return Promise.all([
     indexResp.json(),
diff --git a/landing-pages/src/js/versionSelector.js b/landing-pages/src/js/versionSelector.js
new file mode 100644
index 0000000..316fcda
--- /dev/null
+++ b/landing-pages/src/js/versionSelector.js
@@ -0,0 +1,56 @@
+/**
+ * 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.
+ */
+
+const runVersionSelector = () => {
+  const versionSelectors = window.document.querySelectorAll(".docs-version-selector");
+
+  if (!versionSelectors || versionSelectors.length === 0) {
+    return;
+  }
+
+  fetch("/_gen/docs-index.json")
+    .then((resp) => resp.json())
+    .then(({stable, versions}) => {
+      versionSelectors.forEach((versionSelector) => {
+        const templateText = versionSelector.querySelector("#version-item-template").innerText;
+        let templateElement = document.createElement("div");
+        templateElement.innerHTML = templateText;
+        templateElement = templateElement.firstElementChild;
+
+        const dropdownMenu = versionSelector.querySelector(".dropdown-menu");
+
+
+        const currentVersion = window.document.location.pathname.split("/")[2];
+
+        const appendNewVersionLink = (location, label) => {
+          const newElement = templateElement.cloneNode(true);
+          const newDocsLink = document.location.toString().replace(
+            `/${currentVersion}/`, `/${location}/`
+          );
+          newElement.setAttribute("href", newDocsLink);
+          newElement.innerText = label;
+          dropdownMenu.appendChild(newElement);
+        };
+        appendNewVersionLink("stable", `Stable (${stable})`);
+        versions.forEach((version) => appendNewVersionLink(version, version));
+      });
+    });
+};
+
+runVersionSelector();
diff --git a/site.sh b/site.sh
index 851bd55..e27d23c 100755
--- a/site.sh
+++ b/site.sh
@@ -203,9 +203,14 @@ function run_lint {
     run_command "${script_working_directory}" "${command}" "${DOCKER_PATHS[@]}"
 }
 
+function prepare_docs_index() {
+    run_command "/opt/site/docs-archive/" ./show_docs_index_json.sh > landing-pages/site/static/_gen/docs-index.json
+}
+
 function build_site {
     mkdir -p dist
     rm -rf dist/*
+    prepare_docs_index
     run_command "/opt/site/landing-pages/" npm run build
     cp -R landing-pages/dist/ dist/
     mkdir -p dist/docs/
@@ -291,6 +296,7 @@ if [[ "${CMD}" == "install-node-deps" ]] ; then
 elif [[ "${CMD}" == "preview" ]]; then
     ensure_node_module_exists
     run_command "/opt/site/landing-pages/" npm run index
+    prepare_docs_index
     run_command "/opt/site/landing-pages/" npm run preview
 elif [[ "${CMD}" == "build-landing-pages" ]]; then
     ensure_node_module_exists
diff --git a/sphinx_airflow_theme/demo/conf.py b/sphinx_airflow_theme/demo/conf.py
index 44cc1a5..e3eafd5 100644
--- a/sphinx_airflow_theme/demo/conf.py
+++ b/sphinx_airflow_theme/demo/conf.py
@@ -15,6 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
+import os
 # Configuration file for the Sphinx documentation builder.
 #
 # This file only contains a selection of the most common options. For a full
@@ -37,7 +38,7 @@
 project = 'Theme demo'
 copyright = '2019, Apache Software Foundation'
 author = 'Apache Software Foundation'
-
+version = os.environ.get('RELEASE_VERSION', 'latest')
 
 # -- General configuration ---------------------------------------------------
 
diff --git a/sphinx_airflow_theme/sphinx_airflow_theme/__init__.py b/sphinx_airflow_theme/sphinx_airflow_theme/__init__.py
index 7165840..5132835 100644
--- a/sphinx_airflow_theme/sphinx_airflow_theme/__init__.py
+++ b/sphinx_airflow_theme/sphinx_airflow_theme/__init__.py
@@ -31,4 +31,3 @@ def get_html_theme_path():
 def setup(app):
     app.add_html_theme('sphinx_airflow_theme', path.abspath(path.dirname(__file__)))
     app.add_stylesheet('_gen/css//main-custom.min.css')
-    app.add_js_file('_gen/js/docs.js')
diff --git a/sphinx_airflow_theme/sphinx_airflow_theme/version-selector.html b/sphinx_airflow_theme/sphinx_airflow_theme/version-selector.html
index d5e400a..253c7b1 100644
--- a/sphinx_airflow_theme/sphinx_airflow_theme/version-selector.html
+++ b/sphinx_airflow_theme/sphinx_airflow_theme/version-selector.html
@@ -17,17 +17,15 @@
  under the License.
 #}
 
-<div id="version-selector" class="sidebar__version-selector">
-    <a class="dropdown-toggle" href="#" id="versionDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
-        <span class="bodytext__medium--greyish-brown">Version: </span><span id="selected-version">undefined</span>
+<div id="docs-version-selector" class="docs-version-selector sidebar__version-selector">
+    <a class="dropdown-toggle" href="#" id="versionDropdown" role="button" data-toggle="dropdown" aria-haspopup="true"
+       aria-expanded="false">
+        <span class="bodytext__medium--greyish-brown">Version: </span><span class="version">{{ version }}</span>
     </a>
-    <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(15px, 33px, 0px);">
-        <a class="dropdown-item" href="/docs/1.10.1">1.10.1</a>
-        <a class="dropdown-item" href="/docs/1.10.2">1.10.2</a>
-        <a class="dropdown-item" href="/docs/1.10.3">1.10.3</a>
-        <a class="dropdown-item" href="/docs/1.10.4">1.10.4</a>
-        <a class="dropdown-item" href="/docs/1.10.5">1.10.5</a>
-        <a class="dropdown-item" href="/docs/1.10.6">1.10.6</a>
-        <a class="dropdown-item" href="/docs/1.10.7">1.10.7</a>
+    <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
+
     </div>
+    <script type="application/x-template" id="version-item-template">
+        <a class="dropdown-item"></a>
+    </script>
 </div>