1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00

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.
This commit is contained in:
Markus Lehtonen 2020-10-21 11:42:39 +03:00
parent 502a8c83a9
commit c05c6f2e5b
3 changed files with 41 additions and 27 deletions

View file

@ -40,9 +40,7 @@ remote_theme: rundocs/jekyll-rtd-theme@v2.0.9
# - vendor/gems/ # - vendor/gems/
# - vendor/ruby/ # - vendor/ruby/
# Document versioning. Current 'version' should be listed under # Document versioning
# 'versions' as we use it in constructing the baseurl for other
# versions.
version: master version: master
versions: display_version_list: true
- master

View file

@ -1,30 +1,30 @@
<div class="addons-wrap d-flex flex-column overflow-y-auto"> <div class="addons-wrap d-flex flex-column overflow-y-auto">
<div class="branch"> <div class="branch">
<dl> <dl>
<dt>Versions:</dt> {% if site.display_version_list %}
<dt id="versions">Versions:</dt>
{% comment %} {% comment %}
The following ugly construction is solely for the Drop the last component from site.baseurl which is supposed to
purpose of dropping the "version" suffix from the be pointing to a subdirectory of the true site baseurl.
baseurl. The reason for doing this is that github-pages {% endcomment %}
gem forces us on --safe mode (i.e. disables custom {% assign spliturl = site.baseurl | split: "/" %}
plugins) so we're not able to write a simple ruby {% assign last = spliturl.size | minus: 1 %}
plugin doing delete_suffix() {% assign baseurl = spliturl | slice: 0, last | join: "/" %}
{% endcomment %}
{% assign version_len = site.version | size %} <script src="{{ baseurl }}/versions.js"></script>
{% assign baseurl_len = site.baseurl | size %} <script>
{% assign idx = baseurl_len | minus: version_len %} var dt = document.getElementById('versions');
{% assign suffix = site.baseurl | slice: idx, version_len %} var items = getVersionListItems();
{% if suffix == site.version %} for (var i=0; i < items.length; i++) {
{% assign idx = idx | minus: 1 %} var dd = document.createElement('dd');
{% assign baseurl = site.baseurl | slice: 0, idx %} var a = dd.appendChild(document.createElement('a'));
{% else %} a.appendChild(document.createTextNode(items[i].name));
{% assign baseurl = site.baseurl %} a.href = items[i].url;
dt.appendChild(dd);
}
</script>
{% endif %} {% endif %}
{% for version in site.versions %}
<dd><a href="{{ baseurl }}/{{ version }}/">{{ version }}</a></dd>
{% endfor %}
</dl> </dl>
</div> </div>
<div class="status d-flex flex-justify-between p-2"> <div class="status d-flex flex-justify-between p-2">

View file

@ -14,6 +14,19 @@ Options:
EOF 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 # Argument parsing
# #
@ -106,6 +119,9 @@ cd "$build_dir"
_stable=`(ls -d1 v*/ || :) | sort -n | tail -n1` _stable=`(ls -d1 v*/ || :) | sort -n | tail -n1`
[ -n "$_stable" ] && ln -sfT "$_stable" stable [ -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 if [ -z "`git status --short`" ]; then
echo "No new content, gh-pages branch already up-to-date" echo "No new content, gh-pages branch already up-to-date"
exit 0 exit 0