Skip to content

Commit e917401

Browse files
committed
Make sure term is always set
Fixes #13063
1 parent eb29814 commit e917401

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

‎hugolib/content_map_page.go‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,10 @@ func (sa *sitePagesAssembler) applyAggregatesToTaxonomiesAndTerms() error {
15951595
}
15961596

15971597
func (sa *sitePagesAssembler) assembleTermsAndTranslations() error {
1598+
if sa.pageMap.cfg.taxonomyTermDisabled {
1599+
return nil
1600+
}
1601+
15981602
var (
15991603
pages = sa.pageMap.treePages
16001604
entries = sa.pageMap.treeTaxonomyEntries
@@ -1612,10 +1616,6 @@ func (sa *sitePagesAssembler) assembleTermsAndTranslations() error {
16121616
return false, nil
16131617
}
16141618

1615-
if sa.pageMap.cfg.taxonomyTermDisabled {
1616-
return false, nil
1617-
}
1618-
16191619
for _, viewName := range views {
16201620
vals := types.ToStringSlicePreserveString(getParam(ps, viewName.plural, false))
16211621
if vals == nil {
@@ -1674,6 +1674,7 @@ func (sa *sitePagesAssembler) assembleTermsAndTranslations() error {
16741674
})
16751675
}
16761676
}
1677+
16771678
return false, nil
16781679
},
16791680
}

‎hugolib/page__new.go‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package hugolib
1515

1616
import (
1717
"fmt"
18+
"strings"
1819
"sync"
1920
"sync/atomic"
2021

@@ -140,30 +141,41 @@ func (h *HugoSites) doNewPage(m *pageMeta) (*pageState, *paths.Path, error) {
140141
}
141142
}
142143

144+
var tc viewName
143145
// Identify Page Kind.
144146
if m.pageConfig.Kind == "" {
145147
m.pageConfig.Kind = kinds.KindSection
146148
if m.pathInfo.Base() == "/" {
147149
m.pageConfig.Kind = kinds.KindHome
148150
} else if m.pathInfo.IsBranchBundle() {
149151
// A section, taxonomy or term.
150-
tc := m.s.pageMap.cfg.getTaxonomyConfig(m.Path())
152+
tc = m.s.pageMap.cfg.getTaxonomyConfig(m.Path())
151153
if !tc.IsZero() {
152154
// Either a taxonomy or a term.
153155
if tc.pluralTreeKey == m.Path() {
154156
m.pageConfig.Kind = kinds.KindTaxonomy
155-
m.singular = tc.singular
156157
} else {
157158
m.pageConfig.Kind = kinds.KindTerm
158-
m.term = m.pathInfo.Unnormalized().BaseNameNoIdentifier()
159-
m.singular = tc.singular
160159
}
161160
}
162161
} else if m.f != nil {
163162
m.pageConfig.Kind = kinds.KindPage
164163
}
165164
}
166165

166+
if m.pageConfig.Kind == kinds.KindTerm || m.pageConfig.Kind == kinds.KindTaxonomy {
167+
if tc.IsZero() {
168+
tc = m.s.pageMap.cfg.getTaxonomyConfig(m.Path())
169+
}
170+
if tc.IsZero() {
171+
return nil, fmt.Errorf("no taxonomy configuration found for %q", m.Path())
172+
}
173+
m.singular = tc.singular
174+
if m.pageConfig.Kind == kinds.KindTerm {
175+
m.term = paths.TrimLeading(strings.TrimPrefix(m.pathInfo.Unnormalized().Base(), tc.pluralTreeKey))
176+
}
177+
}
178+
167179
if m.pageConfig.Kind == kinds.KindPage && !m.s.conf.IsKindEnabled(m.pageConfig.Kind) {
168180
return nil, nil
169181
}

‎hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,3 +678,33 @@ summary: {{ .Summary }}|content: {{ .Content}}
678678
"<p>aaa</p>|content: <p>aaa</p>\n<p>bbb</p>",
679679
)
680680
}
681+
682+
// Issue 13063.
683+
func TestPagesFromGoTmplTermIsEmpty(t *testing.T) {
684+
t.Parallel()
685+
686+
files := `
687+
-- hugo.toml --
688+
baseURL = "https://example.com"
689+
disableKinds = ['section', 'home', 'rss','sitemap']
690+
printPathWarnings = true
691+
[taxonomies]
692+
tag = "tags"
693+
-- content/mypost.md --
694+
---
695+
title: "My Post"
696+
tags: ["mytag"]
697+
---
698+
-- content/tags/_content.gotmpl --
699+
{{ .AddPage (dict "path" "mothertag" "title" "My title" "kind" "term") }}
700+
--
701+
-- layouts/_default/taxonomy.html --
702+
Terms: {{ range .Data.Terms.ByCount }}{{ .Name }}: {{ .Count }}|{{ end }}§s
703+
-- layouts/_default/single.html --
704+
Single.
705+
`
706+
707+
b := hugolib.Test(t, files, hugolib.TestOptWarn())
708+
709+
b.AssertFileContent("public/tags/index.html", "Terms: mytag: 1|§s")
710+
}

0 commit comments

Comments
 (0)