Skip to content
Merged
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
24 changes: 14 additions & 10 deletions src/project/types/website/website-navigation-md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,14 @@ const prevPageTitleHandler = (context: NavigationPipelineContext) => {
};
};

const safeKey = (key: string) => {
return md5Hash(key);
};

const breadCrumbHandler = (context: NavigationPipelineContext) => {
return {
getUnrendered() {
if (context.breadCrumbs) {
const markdown: Record<string, string> = {};
for (const item of context.breadCrumbs) {
if (item.text) {
markdown[`${kBreadcrumbPrefix}-${safeKey(item.text)}`] = item.text;
markdown[`${kBreadcrumbPrefix}-${textKey(item.text)}`] = item.text;
}
}
return { inlines: markdown };
Expand All @@ -218,8 +214,8 @@ const breadCrumbHandler = (context: NavigationPipelineContext) => {
);
for (const breadCrumb of breadCrumbs) {
const breadCrumbEl = breadCrumb as Element;
const key = breadCrumbEl.innerText;
const renderedEl = rendered[`${kBreadcrumbPrefix}-${safeKey(key)}`];
const key = breadCrumbEl.innerHTML;
const renderedEl = rendered[`${kBreadcrumbPrefix}-${textKey(key)}`];
if (renderedEl) {
breadCrumbEl.innerHTML = renderedEl.innerHTML;
}
Expand All @@ -228,6 +224,14 @@ const breadCrumbHandler = (context: NavigationPipelineContext) => {
};
};

// TODO: This is a pretty hack workaround to improve our matching in cases like book
// where we inject HTML right into the sidebar. Instead, we really need to switch this
// to requiring that each sidebar item has an id (either user provided or automatically)
// provisioned and then use that id to match for replacement. This is way too brittle and
// terrible
const textKey = (text: string) => {
return text.replaceAll(/\s|&nbsp;/gm, "-").replaceAll(/"/gm, "'");
};
const sidebarContentsHandler = (context: NavigationPipelineContext) => {
return {
getUnrendered() {
Expand All @@ -243,7 +247,7 @@ const sidebarContentsHandler = (context: NavigationPipelineContext) => {
if (item.sectionId) {
markdown[`${kSidebarIdPrefix}${item.sectionId}`] = item.text;
} else {
markdown[`${kSidebarIdPrefix}${item.href}${item.text}`] =
markdown[`${kSidebarIdPrefix}${item.href}${textKey(item.text)}`] =
item.text;
}
}
Expand All @@ -261,8 +265,8 @@ const sidebarContentsHandler = (context: NavigationPipelineContext) => {
const href = sidebarEl.getAttribute("href");
const link = sidebarEl.querySelector(".menu-text");
if (link) {
const sidebarText =
rendered[`${kSidebarIdPrefix}${href}${link.innerText}`];
const text = textKey(link.innerHTML);
const sidebarText = rendered[`${kSidebarIdPrefix}${href}${text}`];
if (sidebarText) {
link.innerHTML = sidebarText.innerHTML;
}
Expand Down