You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.5 KiB
HTML

{{ $context := . }}
{{ $defaults := dict "id" $context.Anchor }}
{{ $max := 0 }}
{{ $new := $context.Level }}
{{ $old := $context.Level }}
{{ $page := $context.Page }}
{{ $attrs := merge $context.Attributes $defaults }}
{{ $store := 0 }}
{{ with $page.Store.Get "paige-render-heading" }}
{{ $max = .max }}
{{ else }}
{{ range $k, $v := $context.Page.Fragments.HeadingsMap }}
{{ if gt $v.Level $max }}
{{ $max = $v.Level }}
{{ end }}
{{ end }}
{{ $page.Store.Set "paige-render-heading" (dict "max" $max) }}
{{ end }}
{{ if and $max (lt $max 6) }}
{{ $new = add $old (sub 6 $max) }}
{{ end }}
{{ if ne $old $new }}
{{ $class := slice }}
{{ $found := false }}
{{ range $k, $v := $attrs }}
{{ if eq $k "class" }}
{{ range split $v " " }}
{{ if . }}
{{ $class = $class | append . }}
{{ if in (slice "h1" "h2" "h3" "h4" "h5" "h6") . }}
{{ $found = true }}
{{ end }}
{{ end }}
{{ end }}
{{ break }}
{{ end }}
{{ end }}
{{ if not $found }}
{{ $class = $class | append (print "h" $new) }}
{{ end }}
{{ $class = delimit (sort $class) " " }}
{{ $attrs = merge (dict "class" $class) $attrs }}
{{ end }}
<h{{ $old }} {{ range $k, $v := $attrs }} {{ printf `%s="%s"` $k $v | safeHTMLAttr }} {{ end }}>
<a class="text-body text-decoration-none" href="#{{ $context.Anchor }}">{{ $context.Text }}</a>
</h{{ $old }}>