From c05c6f2e5b4913897c936e97809083588bd31b6d Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Wed, 21 Oct 2020 11:42:39 +0300 Subject: [PATCH] docs: make the list of available versions dynamic Make the list of available versions dynamic. The items displayed is now generated with javascript. The parent directory of the site is supposed to contain versions.js providing getVersionListItems() that returns the available versions. The update-gh-pages.sh script is modified to update/create versions.js on every invocation. It simply lists all directories in the root directory and adds them to the version list. --- docs/_config.yml | 8 ++--- docs/_includes/class/addons-wrap.liquid | 44 ++++++++++++------------- scripts/github/update-gh-pages.sh | 16 +++++++++ 3 files changed, 41 insertions(+), 27 deletions(-) diff --git a/docs/_config.yml b/docs/_config.yml index 27a689eb0..47137ccad 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -40,9 +40,7 @@ remote_theme: rundocs/jekyll-rtd-theme@v2.0.9 # - vendor/gems/ # - vendor/ruby/ -# Document versioning. Current 'version' should be listed under -# 'versions' as we use it in constructing the baseurl for other -# versions. +# Document versioning version: master -versions: - - master +display_version_list: true + diff --git a/docs/_includes/class/addons-wrap.liquid b/docs/_includes/class/addons-wrap.liquid index 8385205dc..254766d12 100644 --- a/docs/_includes/class/addons-wrap.liquid +++ b/docs/_includes/class/addons-wrap.liquid @@ -1,30 +1,30 @@
-
Versions:
+ {% if site.display_version_list %} +
Versions:
- {% comment %} - The following ugly construction is solely for the - purpose of dropping the "version" suffix from the - baseurl. The reason for doing this is that github-pages - gem forces us on --safe mode (i.e. disables custom - plugins) so we're not able to write a simple ruby - plugin doing delete_suffix() - {% endcomment %} - {% assign version_len = site.version | size %} - {% assign baseurl_len = site.baseurl | size %} - {% assign idx = baseurl_len | minus: version_len %} - {% assign suffix = site.baseurl | slice: idx, version_len %} - {% if suffix == site.version %} - {% assign idx = idx | minus: 1 %} - {% assign baseurl = site.baseurl | slice: 0, idx %} - {% else %} - {% assign baseurl = site.baseurl %} + {% comment %} + Drop the last component from site.baseurl which is supposed to + be pointing to a subdirectory of the true site baseurl. + {% endcomment %} + {% assign spliturl = site.baseurl | split: "/" %} + {% assign last = spliturl.size | minus: 1 %} + {% assign baseurl = spliturl | slice: 0, last | join: "/" %} + + + {% endif %} - - {% for version in site.versions %} -
{{ version }}
- {% endfor %}
diff --git a/scripts/github/update-gh-pages.sh b/scripts/github/update-gh-pages.sh index 15e558279..5c62bd2b7 100755 --- a/scripts/github/update-gh-pages.sh +++ b/scripts/github/update-gh-pages.sh @@ -14,6 +14,19 @@ Options: EOF } +# Helper function for detecting available versions from the current directory +create_versions_js() { + local _baseurl="/node-feature-discovery" + + echo -e "function getVersionListItems() {\n return [" + # 'stable' is a symlink pointing to the latest version + [ -f stable ] && echo " { name: 'stable', url: '$_baseurl/stable' }," + for f in `ls -d */ | tr -d /` ; do + echo " { name: '$f', url: '$_baseurl/$f' }," + done + echo -e " ];\n}" +} + # # Argument parsing # @@ -106,6 +119,9 @@ cd "$build_dir" _stable=`(ls -d1 v*/ || :) | sort -n | tail -n1` [ -n "$_stable" ] && ln -sfT "$_stable" stable +# Detect existing versions from the gh-pages branch +create_versions_js > versions.js + if [ -z "`git status --short`" ]; then echo "No new content, gh-pages branch already up-to-date" exit 0