Feat: add onlyMainSection option for page auto heading numbering

This commit is contained in:
Cell
2024-04-08 17:46:31 +08:00
parent dc0b96210a
commit 6ab33ff7bf
2 changed files with 6 additions and 1 deletions
+2
View File
@@ -698,6 +698,8 @@ enableEmoji = true
[params.page.heading.number]
# whether to enable auto heading numbering
enable = false
# FixIt 0.3.3 | NEW only enable in main section pages (default is posts)
onlyMainSection = true
[params.page.heading.number.format]
h1 = "{title}"
h2 = "{h2} {title}"
+4 -1
View File
@@ -15,7 +15,10 @@
<h{{ .Level }} id="{{ .Anchor | safeURL }}" class="heading-element">
<a href="#{{ .Anchor | safeURL }}" class="heading-mark"></a>
{{- if $params.heading.number.enable -}}
{{- /* Only enable in main section pages */ -}}
{{- $onlyMainSection := cond $params.heading.number.onlyMainSection (eq .Page.Type "posts") true -}}
{{- if $params.heading.number.enable | and $onlyMainSection -}}
{{- /* Add 1 to the current level */ -}}
{{- $headingMap := .Page.Scratch.Get "heading-counter" -}}
{{- $count := (string .Level) | index $headingMap | int | add 1 -}}