Fixup version selector
parent
093e706523
commit
5cf568cfc4
@ -1,25 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
LINES=($(grep -n 'list of versions' version.js | cut -d: -f1))
|
||||
mv -f version.js version.js.bak
|
||||
|
||||
LINES=($(grep -n 'list of versions' version.js.bak | cut -d: -f1))
|
||||
LINES[0]=$(expr ${LINES[0]} - 1)
|
||||
LINES[1]=$(expr ${LINES[1]} + 1)
|
||||
|
||||
VERSIONS=($(find -maxdepth 1 -mindepth 1 -type l) $(find -maxdepth 1 -mindepth 1 -type d))
|
||||
fields=()
|
||||
for version in ${VERSIONS[*]#./}; do
|
||||
label=$(grep "Version" $version/footer.js | sed -r "s/.*'Version ([^']+)'.*/\1/")
|
||||
fields+=("\"${version}\": \"${label}\"")
|
||||
if [ -f "$version/footer.js" ]; then
|
||||
label=$(grep "Version" $version/footer.js | sed -r "s/.*'Version ([^']+)'.*/\1/")
|
||||
fields+=("\"${version}\": \"${label}\"")
|
||||
fi
|
||||
done
|
||||
|
||||
mv version.js version.js.bak
|
||||
|
||||
head -n ${LINES[0]} version.js.bak > version.js
|
||||
echo "//--- list of versions ---" >> version.js
|
||||
echo "const versions = {" >> version.js
|
||||
echo -n " " >> version.js
|
||||
echo $(IFS=,; echo "${fields[*]}") | sed 's/,/,\n /' >> version.js
|
||||
echo $(IFS=,; echo "${fields[*]}") | sed 's/,/,\n /g' >> version.js
|
||||
echo "}" >> version.js
|
||||
echo "//--- list of versions ---" >> version.js
|
||||
tail -n +${LINES[1]} version.js.bak >> version.js
|
||||
|
||||
rm version.js.bak
|
||||
|
||||
exit 0
|
||||
|
||||
@ -1,57 +0,0 @@
|
||||
//--- list of versions ---
|
||||
const versions = {
|
||||
"main": "1.10.2-dev1",
|
||||
"latest": "1.10.1"
|
||||
}
|
||||
//--- list of versions ---
|
||||
|
||||
var scripts = document.getElementsByTagName("script"),
|
||||
scriptUrl = new URL(scripts[scripts.length-1].src);
|
||||
docUrl = new URL(document.URL);
|
||||
baseUrl = new URL(scriptUrl)
|
||||
baseUrl.pathname = baseUrl.pathname.split('/').slice(0,-1).join("/")
|
||||
|
||||
function urlForVersion(url, version) {
|
||||
url = new URL(url);
|
||||
pathname = url.pathname.replace(baseUrl.pathname, "");
|
||||
parts = pathname.split("/");
|
||||
parts[1] = version;
|
||||
url.pathname = baseUrl.pathname + parts.join("/");
|
||||
return url
|
||||
}
|
||||
|
||||
function writeVersionDropdown() {
|
||||
currentVersion = document.currentScript.parentNode.innerText;
|
||||
document.currentScript.parentNode.classList.add("dropdown");
|
||||
document.currentScript.parentNode.innerText = "";
|
||||
document.write(' <span onclick="myFunction()" class="dropbtn">'+currentVersion+'</span>');
|
||||
document.write(' <div id="myDropdown" class="dropdown-content">');
|
||||
for(var version in versions) {
|
||||
var label = versions[version];
|
||||
if (label != version) {
|
||||
label += "("+version+")"
|
||||
}
|
||||
document.write(' <a href="'+urlForVersion(docUrl, version)+'">'+label+'</a>');
|
||||
}
|
||||
document.write(' </div>');
|
||||
};
|
||||
|
||||
/* When the user clicks on the button,
|
||||
toggle between hiding and showing the dropdown content */
|
||||
function myFunction() {
|
||||
document.getElementById("myDropdown").classList.toggle("show");
|
||||
}
|
||||
|
||||
// Close the dropdown menu if the user clicks outside of it
|
||||
window.onclick = function(event) {
|
||||
if (!event.target.matches('.dropbtn')) {
|
||||
var dropdowns = document.getElementsByClassName("dropdown-content");
|
||||
var i;
|
||||
for (i = 0; i < dropdowns.length; i++) {
|
||||
var openDropdown = dropdowns[i];
|
||||
if (openDropdown.classList.contains('show')) {
|
||||
openDropdown.classList.remove('show');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue