Skip to content

Commit 3c1d061

Browse files
committed
fix(docs[spa-nav]): update brand links and logo srcs after SPA navigation
why: The sidebar brand link, mobile header brand link, and logo image srcs use relative paths that go stale after SPA navigation across directory depths. They live outside the swap regions (.article-container, .sidebar-tree, .toc-drawer) so swap() never updates them. what: - After swapping content regions, copy brand href and logo src from the fetched document (which has correct relative paths for the target) - Covers: .sidebar-brand href, .header-center a href, .sidebar-logo src
1 parent 55b085e commit 3c1d061

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

docs/_static/js/spa-nav.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,24 @@
132132
);
133133
var title = doc.querySelector("title");
134134
if (title) document.title = title.textContent || "";
135+
136+
// Brand links and logo images live outside swapped regions.
137+
// Their relative hrefs/srcs go stale after cross-depth navigation.
138+
// Copy the correct values from the fetched document.
139+
[".sidebar-brand", ".header-center a"].forEach(function (sel) {
140+
var fresh = doc.querySelector(sel);
141+
if (!fresh) return;
142+
document.querySelectorAll(sel).forEach(function (el) {
143+
el.setAttribute("href", fresh.getAttribute("href"));
144+
});
145+
});
146+
var freshLogos = doc.querySelectorAll(".sidebar-logo");
147+
var staleLogos = document.querySelectorAll(".sidebar-logo");
148+
freshLogos.forEach(function (fresh, i) {
149+
if (staleLogos[i]) {
150+
staleLogos[i].setAttribute("src", fresh.getAttribute("src"));
151+
}
152+
});
135153
}
136154

137155
function reinit() {

0 commit comments

Comments
 (0)