Skip to content

Commit 778c7cd

Browse files
committed
Check internal links to anchors on other pages
Need to exclude pages that generate headlines from data or Hugo fails, so this kind of check is incomplete
1 parent 78abe80 commit 778c7cd

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

site/themes/arangodb-docs-theme/layouts/_default/_markup/render-link.html

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,30 @@
1818
{{- $permalink = .Destination }}
1919
{{- end }}
2020
{{- else }}
21+
{{- $currentFile := .Page.File.Path }}
2122
{{- $isOnlyFragment := findRE `(?m)^#` $link }}
2223
{{- if $isOnlyFragment }}
23-
{{- $fragments := slice }}
24-
{{- range $k, $v := .Page.Fragments.HeadingsMap }}
25-
{{- $fragments = $fragments | append $k }}
26-
{{- end }}
27-
{{- if not (in $fragments (strings.TrimPrefix "#" $fragment)) }}
28-
{{- $currentFile := .Page.File.Path }}
24+
{{- if not (.Page.Fragments.Identifiers.Contains $url.Fragment) }}
2925
{{- if site.Params.failOnBrokenLinks }}
30-
{{- errorf "<error code=1> Broken anchor link '%v' found in %s, available anchors: %v </error><br>" $fragment $currentFile (delimit $fragments ", ") }}
26+
{{- errorf "<error code=1> Broken anchor link '%v' found in %s, available anchors: %v </error><br>" $fragment $currentFile (delimit .Page.Fragments.Identifiers ", ") }}
3127
{{- else }}
32-
{{- warnf "Broken anchor link '%v' found in %s, available anchors: %v" $fragment $currentPage (delimit $fragments ", ") }}
28+
{{- warnf "Broken anchor link '%v' found in %s, available anchors: %v" $fragment $currentPage (delimit .Page.Fragments.Identifiers ", ") }}
3329
{{- end }}
3430
{{- end }}
3531
{{- $permalink = $fragment }}
3632
{{- else }}
3733
{{- $page := .Page.GetPage $path }}
38-
{{- with $page }}
34+
{{- if $page }}
35+
{{- if and $fragment (not (strings.HasSuffix $path "arangodb-server/options.md")) (not (strings.HasSuffix $path "query-optimization.md")) (not ($page.Fragments.Identifiers.Contains $url.Fragment)) }}
36+
{{- if site.Params.failOnBrokenLinks }}
37+
{{- errorf "<error code=1> Broken anchor link '%v%v' found in %s, available anchors: %v </error><br>" $path $fragment $currentFile (delimit $page.Fragments.Identifiers ", ") }}
38+
{{- else }}
39+
{{- warnf "Broken anchor link '%v%v' found in %s, available anchors: %v" $path $fragment $currentPage (delimit $page.Fragments.Identifiers ", ") }}
40+
{{- end }}
41+
{{- end }}
3942
{{- $permalink = printf "%s%s" $page.RelPermalink $fragment }}
4043
{{- else }}
4144
{{- if ne $currentPage "/" }}
42-
{{- $currentFile := .Page.File.Path }}
4345
{{- if site.Params.failOnBrokenLinks }}
4446
{{- errorf "<error code=1> Broken link '%v' found in %s </error><br>" $link $currentFile }}
4547
{{- else }}

0 commit comments

Comments
 (0)