diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go index 59e25b729..31fbad565 100644 --- a/hugolib/content_map_page.go +++ b/hugolib/content_map_page.go @@ -488,7 +488,7 @@ func (m *pageMap) forEachResourceInPage( prefix := paths.AddTrailingSlash(ps.Path()) - isBranch := ps.IsNode() + isBranch := ps.IsBranch() rwr := &doctree.NodeShiftTreeWalker[contentNode]{ Tree: m.treeResources, diff --git a/hugolib/content_map_page_contentnode.go b/hugolib/content_map_page_contentnode.go index 4df311d3e..2aeb896f8 100644 --- a/hugolib/content_map_page_contentnode.go +++ b/hugolib/content_map_page_contentnode.go @@ -303,7 +303,7 @@ func (h helperContentNode) isBranchNode(n contentNode) bool { case *pageMetaSource: return nn.pathInfo.IsBranchBundle() case *pageState: - return nn.IsNode() + return nn.IsBranch() case contentNodeSampleProvider: return h.isBranchNode(nn.sample()) default: diff --git a/hugolib/page__meta.go b/hugolib/page__meta.go index 755a56d8c..93f85324b 100644 --- a/hugolib/page__meta.go +++ b/hugolib/page__meta.go @@ -469,7 +469,12 @@ func (m *pageMeta) Name() string { } func (m *pageMeta) IsNode() bool { - return !m.IsPage() + hugo.Deprecate(".Page.IsNode", "Use .Page.IsBranch or not .Page.IsPage instead.", "v0.163.0") + return m.IsBranch() +} + +func (m *pageMeta) IsBranch() bool { + return kinds.IsBranch(m.Kind()) } func (m *pageMeta) IsPage() bool { diff --git a/hugolib/page__output.go b/hugolib/page__output.go index 3ba2c1102..979fb755b 100644 --- a/hugolib/page__output.go +++ b/hugolib/page__output.go @@ -48,7 +48,7 @@ func newPageOutput( var paginatorProvider page.PaginatorProvider var pag *pagePaginator - if render && ps.IsNode() { + if render && ps.IsBranch() { pag = newPagePaginator(ps) paginatorProvider = pag } else { diff --git a/hugolib/page_test.go b/hugolib/page_test.go index 08f7729a7..aa4b6c159 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -1994,6 +1994,42 @@ func content(c resource.ContentProvider) string { return ccs } +// See issue 11574. +func TestPageIsBranch(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ["taxonomy", "term", "rss", "sitemap", "robotsTXT", "404"] +-- content/_index.md -- +-- content/sect/_index.md -- +-- content/sect/p1.md -- +-- layouts/all.html -- +{{ .Kind }}|IsBranch={{ .IsBranch }}|IsPage={{ .IsPage }} +` + + b := Test(t, files) + + b.AssertFileContent("public/index.html", "home|IsBranch=true|IsPage=false") + b.AssertFileContent("public/sect/index.html", "section|IsBranch=true|IsPage=false") + b.AssertFileContent("public/sect/p1/index.html", "page|IsBranch=false|IsPage=true") +} + +// See issue 11574. +func TestPageIsNodeDeprecated(t *testing.T) { + files := ` +-- hugo.toml -- +disableKinds = ["taxonomy", "term", "rss", "sitemap", "robotsTXT", "404"] +-- content/_index.md -- +-- layouts/all.html -- +{{ .IsNode }} +` + + b := Test(t, files, TestOptInfo()) + + b.AssertLogContains(".Page.IsNode was deprecated") +} + func BenchmarkIsTranslatedOneLanguage(b *testing.B) { // Set it reasonably high to get a balance between cached and uncached calls to IsTranslated. const numPages = 3000 diff --git a/resources/page/page.go b/resources/page/page.go index f764e7d13..6104eb0ed 100644 --- a/resources/page/page.go +++ b/resources/page/page.go @@ -221,10 +221,15 @@ type PageMetaProvider interface { // The title used for links. LinkTitle() string - // IsNode returns whether this is an item of one of the list types in Hugo, - // i.e. not a regular content + // IsNode returns whether this is a branch node (e.g. a section). + // + // Deprecated: Use IsBranch or "not IsPage" instead. IsNode() bool + // IsBranch returns whether this is a branch node, i.e. a node that + // can have descendants (home, section, taxonomy or term). + IsBranch() bool + // IsPage returns whether this is a regular content IsPage() bool diff --git a/resources/page/page_generate/generate_page_wrappers.go b/resources/page/page_generate/generate_page_wrappers.go index 87e766a7e..f1f288f89 100644 --- a/resources/page/page_generate/generate_page_wrappers.go +++ b/resources/page/page_generate/generate_page_wrappers.go @@ -80,6 +80,7 @@ func generateMarshalJSON(c *codegen.Inspector) error { "github.com/gohugoio/hugo/resources/page", // Exclusion regexps. Matches method names. `\bPage\b`, + `\bIsNode\b`, ) fmt.Fprintf(f, `%s diff --git a/resources/page/page_marshaljson.autogen.go b/resources/page/page_marshaljson.autogen.go index 3b2138801..afe595754 100644 --- a/resources/page/page_marshaljson.autogen.go +++ b/resources/page/page_marshaljson.autogen.go @@ -26,7 +26,6 @@ func MarshalPageToJSON(p Page) ([]byte, error) { lastmod := p.Lastmod() publishDate := p.PublishDate() expiryDate := p.ExpiryDate() - aliases := p.Aliases() bundleType := p.BundleType() description := p.Description() draft := p.Draft() @@ -36,10 +35,10 @@ func MarshalPageToJSON(p Page) ([]byte, error) { layout := p.Layout() linkTitle := p.LinkTitle() isNode := p.IsNode() + isBranch := p.IsBranch() isPage := p.IsPage() path := p.Path() slug := p.Slug() - lang := p.Lang() isSection := p.IsSection() section := p.Section() sitemap := p.Sitemap() @@ -51,7 +50,6 @@ func MarshalPageToJSON(p Page) ([]byte, error) { Lastmod time.Time PublishDate time.Time ExpiryDate time.Time - Aliases []string BundleType string Description string Draft bool @@ -61,10 +59,10 @@ func MarshalPageToJSON(p Page) ([]byte, error) { Layout string LinkTitle string IsNode bool + IsBranch bool IsPage bool Path string Slug string - Lang string IsSection bool Section string Sitemap config.SitemapConfig @@ -75,7 +73,6 @@ func MarshalPageToJSON(p Page) ([]byte, error) { Lastmod: lastmod, PublishDate: publishDate, ExpiryDate: expiryDate, - Aliases: aliases, BundleType: bundleType, Description: description, Draft: draft, @@ -85,10 +82,10 @@ func MarshalPageToJSON(p Page) ([]byte, error) { Layout: layout, LinkTitle: linkTitle, IsNode: isNode, + IsBranch: isBranch, IsPage: isPage, Path: path, Slug: slug, - Lang: lang, IsSection: isSection, Section: section, Sitemap: sitemap, diff --git a/resources/page/page_nop.go b/resources/page/page_nop.go index 900857902..7dbc5f615 100644 --- a/resources/page/page_nop.go +++ b/resources/page/page_nop.go @@ -227,6 +227,10 @@ func (p *nopPage) IsNode() bool { return false } +func (p *nopPage) IsBranch() bool { + return false +} + func (p *nopPage) IsPage() bool { return false } diff --git a/resources/page/testhelpers_test.go b/resources/page/testhelpers_test.go index e6bae5b3b..d41fe6ec1 100644 --- a/resources/page/testhelpers_test.go +++ b/resources/page/testhelpers_test.go @@ -281,6 +281,10 @@ func (p *testPage) IsNode() bool { panic("testpage: not implemented") } +func (p *testPage) IsBranch() bool { + panic("testpage: not implemented") +} + func (p *testPage) IsPage() bool { panic("testpage: not implemented") } diff --git a/tpl/template.go b/tpl/template.go index 1708adc75..e36d203b6 100644 --- a/tpl/template.go +++ b/tpl/template.go @@ -95,7 +95,7 @@ type StringBool struct { } type page interface { - IsNode() bool + IsBranch() bool } type site interface {