diff --git a/Dockerfile b/Dockerfile index 585cbc78dfe..d338ebced3f 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/docs-archive/show_docs_index_json.sh b/docs-archive/show_docs_index_json.sh new file mode 100755 index 00000000000..297d737f4f1 --- /dev/null +++ b/docs-archive/show_docs_index_json.sh @@ -0,0 +1,30 @@ +#!/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 +# 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. + +set -euo pipefail + +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) + +popd &>/dev/null || exit 1 diff --git a/landing-pages/.gitignore b/landing-pages/.gitignore index c8b191ff5b7..4aa6c9e0db9 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 69ec28fec3e..495b5fc585b 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/site/assets/scss/_dropdown.scss b/landing-pages/site/assets/scss/_dropdown.scss new file mode 100644 index 00000000000..888d67c719c --- /dev/null +++ b/landing-pages/site/assets/scss/_dropdown.scss @@ -0,0 +1,36 @@ +/** + * 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. + */ +@import "fonts"; +@import "colors"; + +.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 8a1ed45fec1..7b06c2a9703 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/landing-pages/site/layouts/partials/version-selector.html b/landing-pages/site/layouts/partials/version-selector.html new file mode 100644 index 00000000000..63db3e9971c --- /dev/null +++ b/landing-pages/site/layouts/partials/version-selector.html @@ -0,0 +1,31 @@ +{{/* + 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. +*/}} + + 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 884ea655ddb..7c0917e4511 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 9a871e75139..2ebe0237598 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 85fe4435c15..5cd516e1bde 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 00000000000..316fcda2578 --- /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 851bd55fae9..e27d23c8691 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 44cc1a5e4b6..e3eafd55b30 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 71658403270..51328357e4c 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 d5e400ad6f8..253c7b163b9 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. #} -