Skip to content

Commit

Permalink
docs: fix version picker for previous versions (#5152)
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin Hicks authored Apr 23, 2020
1 parent e8a2a63 commit e10a6c0
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion docs/js/extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,29 @@
var nav = document.querySelector('nav');
var select = document.createElement('select');

var segs = window.location.pathname.split('/');
var currVersion = segs.reduce(function(acc, seg) {
if (LANGS.indexOf(acc.prev) > -1) {
acc.version = seg;
}
acc.prev = seg;
return acc;
}, {prev: '', version: null}).version;

if (!currVersion) {
console.warn('Version selector could not infer the current version. Are you running in a local development environment?');
return;
}

if (currVersion === 'latest') {
currVersion = config.defaultVersion;
}

config.versions.forEach(function(v) {
var option = document.createElement('option');
option.value = v;
option.innerText = v;
option.selected = v === config.defaultVersion;
option.selected = v === currVersion;

select.append(option);
});
Expand Down

0 comments on commit e10a6c0

Please sign in to comment.