RenderHooks: Reconfigure the heading hashes

Instead of a single hash in the left gutter, draw <n> hashes where <n> is the
heading level. All of these hashes are part of the anchor text.
This commit is contained in:
Eryn Wells 2024-07-20 17:29:49 -07:00
parent c30805127c
commit cce432fe0b
2 changed files with 33 additions and 6 deletions

View file

@ -41,4 +41,28 @@
.content-date {
margin-block-end: var(--space-paragraph);
}
.heading {
display: block flex;
gap: var(--space-s);
grid-column: main-start / main-end;
}
.heading__anchor {
align-self: center;
color: var(--gray5);
font-size: var(--text-m);
justify-content: center;
letter-spacing: -0.2em;
a {
transition: 0.3s color;
}
a:hover {
color: var(--text-color);
text-decoration: none;
transition: 0.3s color;
}
}
}

View file

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