Skip to content

Commit

Permalink
Add version selector (apache#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
mik-laj authored Nov 8, 2019
1 parent 91f760c commit faad101
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 17 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
30 changes: 30 additions & 0 deletions docs-archive/show_docs_index_json.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion landing-pages/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ node_modules/
dist/
site/data/webpack.json
resources/
site/static/indexes/
site/static/_gen/
2 changes: 1 addition & 1 deletion landing-pages/create-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
36 changes: 36 additions & 0 deletions landing-pages/site/assets/scss/_dropdown.scss
Original file line number Diff line number Diff line change
@@ -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;
}
}
1 change: 1 addition & 0 deletions landing-pages/site/assets/scss/main-custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@
@import "rst-content";
@import "pygments";
@import "content-drawer";
@import "dropdown";
31 changes: 31 additions & 0 deletions landing-pages/site/layouts/partials/version-selector.html
Original file line number Diff line number Diff line change
@@ -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.
*/}}

<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">

</div>
<script type="application/x-template" id="version-item-template">
<a class="dropdown-item"></a>
</script>
</div>
File renamed without changes.
1 change: 1 addition & 0 deletions landing-pages/src/docs-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ import "./js/progressTracking";
import "./js/rating";
import "./js/makeTableResponsive";
import "./js/tocTree";
import "./js/versionSelector";
1 change: 1 addition & 0 deletions landing-pages/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions landing-pages/src/js/searchBlogPosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
56 changes: 56 additions & 0 deletions landing-pages/src/js/versionSelector.js
Original file line number Diff line number Diff line change
@@ -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();
6 changes: 6 additions & 0 deletions site.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion sphinx_airflow_theme/demo/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ---------------------------------------------------

Expand Down
1 change: 0 additions & 1 deletion sphinx_airflow_theme/sphinx_airflow_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
20 changes: 9 additions & 11 deletions sphinx_airflow_theme/sphinx_airflow_theme/version-selector.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit faad101

Please sign in to comment.