Skip to content

Commit 03ed1d8

Browse files
authored
Fix anchorlinks using Hugo link render hooks (#25)
Hugo link render hooks contain a variable reference to the current page. Using this we can prepend the current page's path to header anchor links. This fixes the issue where all anchorlinks for headers link back to the site homepage.
1 parent 6f22f7d commit 03ed1d8

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<h{{ .Level }} id="{{ .Anchor | safeURL }}">
2+
{{ .Text | safeHTML -}}
3+
<a class="anchor" href="{{ .Page.Path }}/#{{ .Anchor }}">#</a>
4+
</h{{ .Level }}>

site/layouts/docs/single.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ <h1>{{ .Title }}</h1>
3131
{{ partial "sidebar/docs-toc.html" . }}
3232
</nav>
3333
{{ end -}}
34-
{{ partial "main/headline-hash.html" .Content }}
34+
{{ .Content | safeHTML }}
3535
{{ if .Site.Params.editPage -}}
3636
{{ partial "main/edit-page.html" . }}
3737
{{ end -}}

site/layouts/partials/main/headline-hash.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)