Allow disabling header anchors with page and element params

Set params.renderHeadingAnchors = false to disable for a whole page.
Set the element attribute anchor = false to disable for a single heading.
This commit is contained in:
Eryn Wells 2024-07-06 10:18:51 -07:00
parent 6d0fd81a7b
commit 576e7cb485

View file

@ -1,3 +1,8 @@
<h{{ .Level }} id="{{ .Anchor }}" class="heading">
{{ .Text | safeHTML }} <a class="heading__anchor" href="#{{ .Anchor }}">#</a>
{{ .Text | safeHTML }}
{{- $pageWantsAnchors := .Page.Params.renderHeadingAnchors | default true -}}
{{- $anchorEnabledForThisHeading := .Attributes.anchor | default true -}}
{{- if and $pageWantsAnchors $anchorEnabledForThisHeading -}}
<a class="heading__anchor" href="#{{ .Anchor }}">#</a>
{{- end -}}
</h{{ .Level }}>