1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-03-31 04:04:51 +00:00

Merge pull request #371 from marquiz/documentation/dynamic-version-menu

docs: make the list of available versions dynamic
This commit is contained in:
Kubernetes Prow Robot 2020-10-29 13:08:07 -07:00 committed by GitHub
commit 12b6812456
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 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
# #
@ -103,6 +116,12 @@ fi
# Switch to work in the gh-pages worktree # Switch to work in the gh-pages worktree
cd "$build_dir" 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 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