Feat: add hugo.mainSections param support (#590)

https://gohugo.io/methods/site/mainsections/
This commit is contained in:
Cell
2025-04-25 12:55:03 +08:00
committed by GitHub
parent 450e774d3c
commit b45ab833d5
3 changed files with 7 additions and 3 deletions
+2
View File
@@ -34,6 +34,8 @@ enableRobotsTXT = true
enableGitInfo = true
# whether to use emoji code
enableEmoji = true
# the main sections of a site
mainSections = []
# -------------------------------------------------------------------------------------
# Menu Configuration
+2 -1
View File
@@ -7,7 +7,8 @@
{{- end -}}
{{- $headingConfig := $params.heading -}}
{{- /* Only enable in main section pages */ -}}
{{- $onlyMainSection := cond $headingConfig.number.onlyMainSection (eq .Page.Type "posts") true -}}
{{- $intersect := (slice .Page.Section .Page.Type) | intersect site.MainSections -}}
{{- $onlyMainSection := cond $headingConfig.number.onlyMainSection ((gt (len $intersect) 0) | and (eq .Page.Kind "page")) true -}}
{{- $ordered := $toc.ordered | and $headingConfig.number.enable | and $onlyMainSection -}}
{{- $h1Format := $headingConfig.number.format.h1 | default "{title}" -}}
{{- $h2Format := $headingConfig.number.format.h2 | default "{h2} {title}" -}}
+3 -2
View File
@@ -4,8 +4,9 @@
{{- $homeRelPermalink = strings.TrimSuffix "offline/" $homeRelPermalink -}}
{{- .Scratch.Set "homeRelPermalink" $homeRelPermalink -}}
{{- /* Set pages of main section */ -}}
{{- $pages := where .Site.RegularPages "Type" "posts" -}}
{{- /* Set pages of main sections */ -}}
{{- $pages := where .Site.RegularPages "Section" "in" .Site.MainSections -}}
{{- $pages = $pages | union (where .Site.RegularPages "Type" "in" .Site.MainSections) -}}
{{- .Scratch.Set "mainSectionPages" $pages -}}
{{- /* Select the scope named `public_repo` to generate personal access token */ -}}