Skip to content

Commit

Permalink
fix anchor links
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Feb 2, 2024
1 parent 846ae53 commit 3821fe2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions build/curriculum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,11 @@ export async function buildModule(document: BuildData): Promise<Doc> {
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);
Expand Down
5 changes: 3 additions & 2 deletions build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand All @@ -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}` : ""}`);
});
}

Expand Down

0 comments on commit 3821fe2

Please sign in to comment.