Skip to content

Commit 1400a42

Browse files
author
aleroux
committed
chore: PRSDM-7843 - Migrate latest changes from pdf-theme
1 parent b6bb351 commit 1400a42

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

layouts/partials/pdf/article.html

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,10 @@
1212
{{ $path = replace $path $permalinkSlug $slug }}
1313
{{ end }}
1414

15-
{{ $fileSlug := anchorize .context.File.BaseFileName }}
16-
{{ $fileSlugAlt := replaceRE `^\d+-` "" .context.File.BaseFileName }}
17-
{{ if eq .context.File.BaseFileName "_index" }}
18-
{{ $fileSlug = (partial "pdf/common/parent-slug" .context) }}
19-
{{ $fileSlugAlt = replaceRE `^\d+-` "" $fileSlug }}
20-
{{ end }}
21-
2215
<div class="presidium-article-wrapper">
2316
{{ if ne .context.Parent.Title .context.Title}}
24-
<h{{ $depth }} class="article-title" id="{{ $slug }}">{{ .context.Title }}</h{{ $depth }}>
17+
<span id="{{ $slug }}"></span>
18+
<h{{ $depth }} class="article-title" id="{{ $path }}">{{ .context.Title }}</h{{ $depth }}>
2519
{{ end }}
2620
{{ .context.Content }}
2721
</div>

static/links.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,28 @@ for (var i = 0; i < links.length; i++) {
2222
continue;
2323
}
2424

25-
href = href.replace(baseURL, "");
26-
27-
if (href.indexOf("#") === 0) {
28-
continue;
29-
}
25+
// Normalize the URL by removing trailing slash before hash
26+
href = href.replace(baseURL, "").replace(/\/(?=#)/, "");
3027

3128
var segments = href.split("/").filter(function(x) {
3229
return x;
3330
});
3431

35-
var anchor = segments.pop();
32+
// slugify the segments by replacing slashes and hashes with dashes
33+
var newAnchor = segments.map(function(x) {
34+
return x.replace("/", "-").replace("#", "-");
35+
}).join("-");
3636

37-
if (anchor.indexOf("#") === 0) {
38-
anchor = anchor.substring(1);
39-
}
37+
var match = document.getElementById(newAnchor);
4038

41-
var match = document.getElementById(anchor);
39+
// If the article exists, link to it instead of the original URL
4240
if (match) {
43-
link.href = "#" + anchor;
41+
link.href = "#" + newAnchor;
4442
}
45-
}
43+
else {
44+
// If the article doesn't exist, link to the link hash instead
45+
if (!link.hash == "") {
46+
link.href = link.hash
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)