File tree Expand file tree Collapse file tree 2 files changed +18
-20
lines changed Expand file tree Collapse file tree 2 files changed +18
-20
lines changed Original file line number Diff line number Diff line change 12
12
{{ $path = replace $path $permalinkSlug $slug }}
13
13
{{ end }}
14
14
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
-
22
15
< div class ="presidium-article-wrapper ">
23
16
{{ 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 }}>
25
19
{{ end }}
26
20
{{ .context.Content }}
27
21
</ div >
Original file line number Diff line number Diff line change @@ -22,24 +22,28 @@ for (var i = 0; i < links.length; i++) {
22
22
continue ;
23
23
}
24
24
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 ( / \/ (? = # ) / , "" ) ;
30
27
31
28
var segments = href . split ( "/" ) . filter ( function ( x ) {
32
29
return x ;
33
30
} ) ;
34
31
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 ( "-" ) ;
36
36
37
- if ( anchor . indexOf ( "#" ) === 0 ) {
38
- anchor = anchor . substring ( 1 ) ;
39
- }
37
+ var match = document . getElementById ( newAnchor ) ;
40
38
41
- var match = document . getElementById ( anchor ) ;
39
+ // If the article exists, link to it instead of the original URL
42
40
if ( match ) {
43
- link . href = "#" + anchor ;
41
+ link . href = "#" + newAnchor ;
44
42
}
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
+ }
You can’t perform that action at this time.
0 commit comments