Skip to content

Commit 877de71

Browse files
committed
Use the rendered sidebar contents for the breadcrumbs when possible
1 parent c15360b commit 877de71

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/project/types/website/website-navigation.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ export async function websiteNavigationExtras(
285285
if (navigation.footer) {
286286
nav.footer = navigation.footer;
287287
}
288+
288289
// determine whether to show the dark toggle
289290
const darkMode = formatDarkMode(format);
290291
if (darkMode !== undefined && nav.navbar) {
@@ -465,8 +466,19 @@ function navigationHtmlPostprocessor(
465466
};
466467

467468
if (navigation.breadCrumbs && navigation.breadCrumbs.length > 0) {
469+
let crumbCount = 0;
468470
for (const item of navigation.breadCrumbs) {
469471
if (item.text || item.icon) {
472+
// Attempt to use the item's title, if possible
473+
let titleEl;
474+
if (item.id) {
475+
titleEl = doc.getElementById(item.id);
476+
} else if (item.href) {
477+
titleEl = doc.querySelector(
478+
`.depth${crumbCount} .sidebar-item a[href="${item.href}"] .menu-text`,
479+
);
480+
}
481+
470482
const liEl = breadCrumbEl();
471483
const maybeLink = (liEl: Element, contents: Element | string) => {
472484
if (item.href) {
@@ -482,7 +494,7 @@ function navigationHtmlPostprocessor(
482494
return liEl;
483495
} else {
484496
if (typeof (contents) === "string") {
485-
liEl.innerText = item.text || "";
497+
liEl.innerHTML = item.text || "";
486498
} else {
487499
liEl.appendChild(contents);
488500
}
@@ -492,7 +504,12 @@ function navigationHtmlPostprocessor(
492504
};
493505

494506
if (item.text) {
495-
olEl.appendChild(maybeLink(liEl, item.text || ""));
507+
olEl.appendChild(
508+
maybeLink(
509+
liEl,
510+
titleEl ? titleEl.innerHTML : (item.text || ""),
511+
),
512+
);
496513
} else if (item.icon) {
497514
const iconEl = doc.createElement("i");
498515
iconEl.classList.add("bi");
@@ -501,6 +518,7 @@ function navigationHtmlPostprocessor(
501518
olEl.appendChild(maybeLink(liEl, iconEl));
502519
}
503520
}
521+
crumbCount++;
504522
}
505523
} else {
506524
const sidebarTitle = doc.querySelector(".sidebar-title a");

0 commit comments

Comments
 (0)