Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 15 additions & 35 deletions docfx_project/public/version-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,40 +49,18 @@
}

function renderPicker(versions) {
// Detect the currently-viewed version from the URL.
var currentVersion = 'latest';
// Detect the currently-viewed version strictly from the URL: only
// pages under /versions/<v>/ get a currentVersion; every other
// path (site root, the redirect stub, docfx-serve non-versioned
// preview) leaves it null. That way the "include latest" check
// below fires only on /versions/latest/ specifically — nowhere
// else — and no option gets .selected on non-versioned pages.
var currentVersion = null;
var m = window.location.pathname.match(/\/versions\/([^\/]+)(?:\/|$)/);
if (m) {
currentVersion = m[1];
}

// If we're on /versions/latest/, resolve 'latest' to the concrete
// version it points to (matching the `latest` entry's url against
// the versioned entries). Without this resolution, the browser
// auto-selects the first option in the dropdown — which is usually
// the same concrete version 'latest' aliases — and picking that
// option doesn't fire `change`, leaving the user unable to navigate
// away from /versions/latest/ to the equivalent concrete-version
// URL via the picker.
if (currentVersion === 'latest') {
var latestEntry = null;
for (var i = 0; i < versions.length; i++) {
if (versions[i] && versions[i].version === 'latest') {
latestEntry = versions[i];
break;
}
}
if (latestEntry && latestEntry.url) {
for (var j = 0; j < versions.length; j++) {
var v = versions[j];
if (v && v.version !== 'latest' && v.url === latestEntry.url) {
currentVersion = v.version;
break;
}
}
}
}

// Build the <select>.
var select = document.createElement('select');
select.className = 'wolfgang-version-picker';
Expand Down Expand Up @@ -113,12 +91,14 @@
var optionCount = 0;
versions.forEach(function (v) {
if (!v || !v.version || !v.url) return;
// Skip the "latest" alias — the highest-numbered v* entry
// already represents the latest release; surfacing both is
// redundant in the picker. versions.json keeps the "latest"
// entry so other consumers (links, scripts) can still
// resolve it.
if (v.version === 'latest') return;
// Skip the "latest" alias EXCEPT when the reader is actually
// on /versions/latest/. On every other page the highest-
// numbered v* entry already represents the latest release
// and surfacing both is redundant; on /versions/latest/ we
// NEED `latest` in the list because otherwise the picker
// would show no selected option and the reader would have
// no way to know which version they are viewing.
if (v.version === 'latest' && currentVersion !== 'latest') return;
Comment thread
Chris-Wolfgang marked this conversation as resolved.
var opt = document.createElement('option');
opt.value = v.url;
opt.textContent = v.version;
Expand Down
11 changes: 8 additions & 3 deletions docs/DOCFX-VERSION-PICKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ downstream `.NET` repo in the fleet.
| `/<repo>/versions/latest/` (or any version) | Real DocFX docs render. The header shows a `<select>` between the app title and the theme toggle, populated from `versions.json` and pre-selecting whichever version the current URL is under. |
| Pick a different version in the dropdown | Browser navigates to `/<repo>/versions/<picked>/` |

The "latest" alias is filtered out of the dropdown (redundant — the
highest-numbered `v*` row already represents latest); `versions.json`
still includes it so external links / scripts can resolve it.
The "latest" alias is filtered out of the dropdown on every version-specific
page — the highest-numbered `v*` row already represents latest, so surfacing
both is redundant. The **exception** is `/versions/latest/` itself: on that
page the picker DOES include the `latest` row so it has an option to
pre-select. Without the exception the dropdown would render with nothing
selected and the reader would have no visual cue for which version they are
viewing. `versions.json` still includes `latest` regardless so external links
/ scripts can resolve it.

---

Expand Down
Loading