|
49 | 49 | } |
50 | 50 |
|
51 | 51 | function renderPicker(versions) { |
52 | | - // Detect the currently-viewed version from the URL. |
53 | | - var currentVersion = 'latest'; |
| 52 | + // Detect the currently-viewed version from the URL. Starts as null and |
| 53 | + // is only set when the URL actually matches /versions/<v>/. Root and |
| 54 | + // other non-versioned pages leave it null — that way the `latest` |
| 55 | + // alias entry stays out of the picker except on /versions/latest/, |
| 56 | + // and no option gets pre-selected when we can't identify the version. |
| 57 | + var currentVersion = null; |
54 | 58 | var m = window.location.pathname.match(/\/versions\/([^\/]+)(?:\/|$)/); |
55 | 59 | if (m) { |
56 | 60 | currentVersion = m[1]; |
57 | 61 | } |
58 | 62 |
|
59 | | - // If we're on /versions/latest/, resolve 'latest' to the concrete |
60 | | - // version it points to (matching the `latest` entry's url against |
61 | | - // the versioned entries). Without this resolution, the browser |
62 | | - // auto-selects the first option in the dropdown — which is usually |
63 | | - // the same concrete version 'latest' aliases — and picking that |
64 | | - // option doesn't fire `change`, leaving the user unable to navigate |
65 | | - // away from /versions/latest/ to the equivalent concrete-version |
66 | | - // URL via the picker. |
67 | | - if (currentVersion === 'latest') { |
68 | | - var latestEntry = null; |
69 | | - for (var i = 0; i < versions.length; i++) { |
70 | | - if (versions[i] && versions[i].version === 'latest') { |
71 | | - latestEntry = versions[i]; |
72 | | - break; |
73 | | - } |
74 | | - } |
75 | | - if (latestEntry && latestEntry.url) { |
76 | | - for (var j = 0; j < versions.length; j++) { |
77 | | - var v = versions[j]; |
78 | | - if (v && v.version !== 'latest' && v.url === latestEntry.url) { |
79 | | - currentVersion = v.version; |
80 | | - break; |
81 | | - } |
82 | | - } |
83 | | - } |
84 | | - } |
85 | | - |
86 | 63 | // Build the <select>. |
87 | 64 | var select = document.createElement('select'); |
88 | 65 | select.className = 'wolfgang-version-picker'; |
|
113 | 90 | var optionCount = 0; |
114 | 91 | versions.forEach(function (v) { |
115 | 92 | if (!v || !v.version || !v.url) return; |
116 | | - // Skip the "latest" alias — the highest-numbered v* entry |
117 | | - // already represents the latest release; surfacing both is |
118 | | - // redundant in the picker. versions.json keeps the "latest" |
119 | | - // entry so other consumers (links, scripts) can still |
120 | | - // resolve it. |
121 | | - if (v.version === 'latest') return; |
| 93 | + // Skip the "latest" alias EXCEPT when the reader is actually |
| 94 | + // on /versions/latest/. On every other page the highest- |
| 95 | + // numbered v* entry already represents the latest release |
| 96 | + // and surfacing both is redundant; on /versions/latest/ we |
| 97 | + // NEED `latest` in the list because otherwise the picker |
| 98 | + // would show no selected option and the reader would have |
| 99 | + // no way to know which version they are viewing. |
| 100 | + if (v.version === 'latest' && currentVersion !== 'latest') return; |
122 | 101 | var opt = document.createElement('option'); |
123 | 102 | opt.value = v.url; |
124 | 103 | opt.textContent = v.version; |
|
0 commit comments