diff --git a/build/curriculum.ts b/build/curriculum.ts index db625aa995e1..85cceb22da1b 100644 --- a/build/curriculum.ts +++ b/build/curriculum.ts @@ -275,10 +275,11 @@ export async function buildModule(document: BuildData): Promise { injectNoTranslate($); injectLoadingLazyAttributes($); postProcessCurriculumLinks($, (p: string) => { + const [head, hash] = p.split("#"); const slug = fileToSlug( - path.normalize(path.join(path.dirname(document.fileInfo.path), p)) + path.normalize(path.join(path.dirname(document.fileInfo.path), head)) ).replace(/\/$/, ""); - return `/${DEFAULT_LOCALE}/${slug}/`; + return `/${DEFAULT_LOCALE}/${slug}/${hash ? `#${hash}` : ""}`; }); postProcessExternalLinks($); postLocalFileLinks($, doc); diff --git a/build/utils.ts b/build/utils.ts index 0c9e7fe0adc3..302b1304405b 100644 --- a/build/utils.ts +++ b/build/utils.ts @@ -246,7 +246,7 @@ export function postProcessExternalLinks($) { * @param {current url} url */ export function postProcessCurriculumLinks($, toUrl) { - $("a[href^=./]").each((_, element) => { + $("a[href^=.]").each((_, element) => { // Expand relative links (TODO: fix) const $a = $(element); $a.attr("href", toUrl($a.attr("href"))); @@ -261,7 +261,8 @@ export function postProcessCurriculumLinks($, toUrl) { }); $("a[href^=/en-US/curriculum]").each((_, element) => { const $a = $(element); - $a.attr("href", $a.attr("href").replace(/\d+-/g, "")); + const [head, hash] = $a.attr("href").split("#"); + $a.attr("href", `${head.replace(/\d+-/g, "")}${hash ? `#${hash}` : ""}`); }); }