From 014e1fa67ccbc0493f4e1641fb2a439e0c4f8aa6 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Sun, 17 Aug 2025 15:13:14 +0800 Subject: [PATCH] :sparkles: Feat: add page param `decreaseH1` to decrease the H1 heading level in content --- hugo.toml | 2 ++ layouts/_markup/render-heading.html | 7 ++++--- layouts/_partials/init/index.html | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/hugo.toml b/hugo.toml index f1c8f57e..d7c3c509 100644 --- a/hugo.toml +++ b/hugo.toml @@ -1070,6 +1070,8 @@ mainSections = [] ordered = false startLevel = 2 endLevel = 6 + # FixIt 0.4.0 | NEW whether to decrease the H1 heading level in content + decreaseH1 = false # FixIt 0.2.13 | NEW Display a message at the beginning of an article to warn the reader that its content might be expired [params.page.expirationReminder] enable = false diff --git a/layouts/_markup/render-heading.html b/layouts/_markup/render-heading.html index bc1609ab..a955eabb 100644 --- a/layouts/_markup/render-heading.html +++ b/layouts/_markup/render-heading.html @@ -17,7 +17,7 @@ {{- $h5Format := $headingConfig.number.format.h5 | default "{h2}.{h3}.{h4}.{h5} {title}" -}} {{- $h6Format := $headingConfig.number.format.h6 | default "{h2}.{h3}.{h4}.{h5}.{h6} {title}" -}} {{- $level := .Level -}} -{{- $maxMarkupLevel := 2 -}} +{{- $maxMarkupLevel := cond $toc.decreaseH1 2 1 -}} {{- /* Disable ordered headings on home page */ -}} {{- if eq hugo.Context.MarkupScope "home" -}} @@ -45,8 +45,9 @@ {{- $attrs = partial "function/trim.html" $attrs -}} {{- /* Force decrease the markup level to avoid multiple h1 */ -}} -{{- $markupLevel := cond (gt $maxMarkupLevel $level) $maxMarkupLevel $level -}} - +{{- $decreased := gt $maxMarkupLevel $level -}} +{{- $markupLevel := cond $decreased $maxMarkupLevel $level -}} + {{- $title := .Text -}} {{- if $ordered -}} {{- /* Add 1 to the current level */ -}} diff --git a/layouts/_partials/init/index.html b/layouts/_partials/init/index.html index 53246bd5..c265b253 100644 --- a/layouts/_partials/init/index.html +++ b/layouts/_partials/init/index.html @@ -1,4 +1,4 @@ -{{- hugo.Store.Set "version" "v0.4.0-alpha-20250814132913-e04bb611" -}} +{{- hugo.Store.Set "version" "v0.4.0-alpha-20250817071316-77fcd7fa" -}} {{- .Store.Set "this" dict -}} {{- partial "init/detection-env.html" . -}}