diff options
author | Bjørn Erik Pedersen <[email protected]> | 2024-11-18 15:01:09 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-11-18 16:20:25 +0100 |
commit | e917401c710d4213e17b7174ed18f042784ff6d6 (patch) | |
tree | 7a15cc25ad03a57c62a78a49ed492f13d8fa97fe /hugolib/page__new.go | |
parent | eb298144b63cfa9e6720ec5731c7687d7df15955 (diff) | |
download | hugo-e917401c710d4213e17b7174ed18f042784ff6d6.tar.gz hugo-e917401c710d4213e17b7174ed18f042784ff6d6.zip |
Make sure term is always set
Fixes #13063
Diffstat (limited to 'hugolib/page__new.go')
-rw-r--r-- | hugolib/page__new.go | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/hugolib/page__new.go b/hugolib/page__new.go index 91bfe5e32..7d948ef58 100644 --- a/hugolib/page__new.go +++ b/hugolib/page__new.go @@ -15,6 +15,7 @@ package hugolib import ( "fmt" + "strings" "sync" "sync/atomic" @@ -140,6 +141,7 @@ func (h *HugoSites) doNewPage(m *pageMeta) (*pageState, *paths.Path, error) { } } + var tc viewName // Identify Page Kind. if m.pageConfig.Kind == "" { m.pageConfig.Kind = kinds.KindSection @@ -147,16 +149,13 @@ func (h *HugoSites) doNewPage(m *pageMeta) (*pageState, *paths.Path, error) { m.pageConfig.Kind = kinds.KindHome } else if m.pathInfo.IsBranchBundle() { // A section, taxonomy or term. - tc := m.s.pageMap.cfg.getTaxonomyConfig(m.Path()) + tc = m.s.pageMap.cfg.getTaxonomyConfig(m.Path()) if !tc.IsZero() { // Either a taxonomy or a term. if tc.pluralTreeKey == m.Path() { m.pageConfig.Kind = kinds.KindTaxonomy - m.singular = tc.singular } else { m.pageConfig.Kind = kinds.KindTerm - m.term = m.pathInfo.Unnormalized().BaseNameNoIdentifier() - m.singular = tc.singular } } } else if m.f != nil { @@ -164,6 +163,19 @@ func (h *HugoSites) doNewPage(m *pageMeta) (*pageState, *paths.Path, error) { } } + if m.pageConfig.Kind == kinds.KindTerm || m.pageConfig.Kind == kinds.KindTaxonomy { + if tc.IsZero() { + tc = m.s.pageMap.cfg.getTaxonomyConfig(m.Path()) + } + if tc.IsZero() { + return nil, fmt.Errorf("no taxonomy configuration found for %q", m.Path()) + } + m.singular = tc.singular + if m.pageConfig.Kind == kinds.KindTerm { + m.term = paths.TrimLeading(strings.TrimPrefix(m.pathInfo.Unnormalized().Base(), tc.pluralTreeKey)) + } + } + if m.pageConfig.Kind == kinds.KindPage && !m.s.conf.IsKindEnabled(m.pageConfig.Kind) { return nil, nil } |