Move all Kind constants to its own package

See #11256
This commit is contained in:
Bjørn Erik Pedersen 2023-07-28 10:53:47 +02:00
parent 5542f02fbc
commit b3cb6788b2
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
35 changed files with 386 additions and 323 deletions

View file

@ -45,6 +45,7 @@ import (
"github.com/gohugoio/hugo/output" "github.com/gohugoio/hugo/output"
"github.com/gohugoio/hugo/related" "github.com/gohugoio/hugo/related"
"github.com/gohugoio/hugo/resources/images" "github.com/gohugoio/hugo/resources/images"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/resources/page/pagemeta" "github.com/gohugoio/hugo/resources/page/pagemeta"
"github.com/spf13/afero" "github.com/spf13/afero"
@ -940,11 +941,11 @@ func createDefaultOutputFormats(allFormats output.Formats) map[string][]string {
} }
m := map[string][]string{ m := map[string][]string{
page.KindPage: {htmlOut.Name}, kinds.KindPage: {htmlOut.Name},
page.KindHome: defaultListTypes, kinds.KindHome: defaultListTypes,
page.KindSection: defaultListTypes, kinds.KindSection: defaultListTypes,
page.KindTerm: defaultListTypes, kinds.KindTerm: defaultListTypes,
page.KindTaxonomy: defaultListTypes, kinds.KindTaxonomy: defaultListTypes,
} }
// May be disabled // May be disabled

View file

@ -22,6 +22,7 @@ import (
"github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/hugofs/files" "github.com/gohugoio/hugo/hugofs/files"
@ -275,13 +276,13 @@ type contentBundleViewInfo struct {
func (c *contentBundleViewInfo) kind() string { func (c *contentBundleViewInfo) kind() string {
if c.termKey != "" { if c.termKey != "" {
return page.KindTerm return kinds.KindTerm
} }
return page.KindTaxonomy return kinds.KindTaxonomy
} }
func (c *contentBundleViewInfo) sections() []string { func (c *contentBundleViewInfo) sections() []string {
if c.kind() == page.KindTaxonomy { if c.kind() == kinds.KindTaxonomy {
return []string{c.name.plural} return []string{c.name.plural}
} }

View file

@ -19,6 +19,7 @@ import (
"path" "path"
"path/filepath" "path/filepath"
"strings" "strings"
"sync" "sync"
"github.com/gohugoio/hugo/common/maps" "github.com/gohugoio/hugo/common/maps"
@ -30,6 +31,7 @@ import (
"github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/hugofs/files" "github.com/gohugoio/hugo/hugofs/files"
"github.com/gohugoio/hugo/parser/pageparser" "github.com/gohugoio/hugo/parser/pageparser"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/resources/resource" "github.com/gohugoio/hugo/resources/resource"
"github.com/spf13/cast" "github.com/spf13/cast"
@ -105,7 +107,7 @@ func (m *pageMap) newPageFromContentNode(n *contentNode, parentBucket *pagesMapB
sections := s.sectionsFromFile(f) sections := s.sectionsFromFile(f)
kind := s.kindFromFileInfoOrSections(f, sections) kind := s.kindFromFileInfoOrSections(f, sections)
if kind == page.KindTerm { if kind == kinds.KindTerm {
s.PathSpec.MakePathsSanitized(sections) s.PathSpec.MakePathsSanitized(sections)
} }
@ -366,7 +368,7 @@ func (m *pageMap) assemblePages() error {
return true return true
} }
shouldBuild = !(n.p.Kind() == page.KindPage && m.cfg.pageDisabled) && m.s.shouldBuild(n.p) shouldBuild = !(n.p.Kind() == kinds.KindPage && m.cfg.pageDisabled) && m.s.shouldBuild(n.p)
if !shouldBuild { if !shouldBuild {
m.deletePage(s) m.deletePage(s)
return false return false
@ -469,9 +471,9 @@ func (m *pageMap) assembleSections() error {
parentBucket = m.s.siteBucket parentBucket = m.s.siteBucket
} }
kind := page.KindSection kind := kinds.KindSection
if s == "/" { if s == "/" {
kind = page.KindHome kind = kinds.KindHome
} }
if n.fi != nil { if n.fi != nil {
@ -537,7 +539,7 @@ func (m *pageMap) assembleTaxonomies() error {
} }
} else { } else {
title := "" title := ""
if kind == page.KindTerm { if kind == kinds.KindTerm {
title = n.viewInfo.term() title = n.viewInfo.term()
} }
n.p = m.s.newPage(n, parent.p.bucket, kind, title, sections...) n.p = m.s.newPage(n, parent.p.bucket, kind, title, sections...)

View file

@ -17,6 +17,7 @@ import (
"testing" "testing"
qt "github.com/frankban/quicktest" qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
) )
@ -134,7 +135,7 @@ title: Headless Local Lists Sub
return nil return nil
} }
disableKind := page.KindPage disableKind := kinds.KindPage
c.Run("Disable "+disableKind, func(c *qt.C) { c.Run("Disable "+disableKind, func(c *qt.C) {
b := newSitesBuilder(c, disableKind) b := newSitesBuilder(c, disableKind)
b.Build(BuildCfg{}) b.Build(BuildCfg{})
@ -149,7 +150,7 @@ title: Headless Local Lists Sub
b.Assert(len(s.Taxonomies()["categories"]), qt.Equals, 0) b.Assert(len(s.Taxonomies()["categories"]), qt.Equals, 0)
}) })
disableKind = page.KindTerm disableKind = kinds.KindTerm
c.Run("Disable "+disableKind, func(c *qt.C) { c.Run("Disable "+disableKind, func(c *qt.C) {
b := newSitesBuilder(c, disableKind) b := newSitesBuilder(c, disableKind)
b.Build(BuildCfg{}) b.Build(BuildCfg{})
@ -161,7 +162,7 @@ title: Headless Local Lists Sub
b.Assert(getPage(b, "/categories/mycat"), qt.IsNil) b.Assert(getPage(b, "/categories/mycat"), qt.IsNil)
}) })
disableKind = page.KindTaxonomy disableKind = kinds.KindTaxonomy
c.Run("Disable "+disableKind, func(c *qt.C) { c.Run("Disable "+disableKind, func(c *qt.C) {
b := newSitesBuilder(c, disableKind) b := newSitesBuilder(c, disableKind)
b.Build(BuildCfg{}) b.Build(BuildCfg{})
@ -177,7 +178,7 @@ title: Headless Local Lists Sub
b.Assert(getPageInPagePages(getPage(b, "/"), "/categories"), qt.IsNil) b.Assert(getPageInPagePages(getPage(b, "/"), "/categories"), qt.IsNil)
}) })
disableKind = page.KindHome disableKind = kinds.KindHome
c.Run("Disable "+disableKind, func(c *qt.C) { c.Run("Disable "+disableKind, func(c *qt.C) {
b := newSitesBuilder(c, disableKind) b := newSitesBuilder(c, disableKind)
b.Build(BuildCfg{}) b.Build(BuildCfg{})
@ -190,7 +191,7 @@ title: Headless Local Lists Sub
b.Assert(getPage(b, "/sect/page.md"), qt.Not(qt.IsNil)) b.Assert(getPage(b, "/sect/page.md"), qt.Not(qt.IsNil))
}) })
disableKind = page.KindSection disableKind = kinds.KindSection
c.Run("Disable "+disableKind, func(c *qt.C) { c.Run("Disable "+disableKind, func(c *qt.C) {
b := newSitesBuilder(c, disableKind) b := newSitesBuilder(c, disableKind)
b.Build(BuildCfg{}) b.Build(BuildCfg{})
@ -210,7 +211,7 @@ title: Headless Local Lists Sub
b.AssertFileContent("public/index.xml", "rss") b.AssertFileContent("public/index.xml", "rss")
}) })
disableKind = kindRSS disableKind = kinds.KindRSS
c.Run("Disable "+disableKind, func(c *qt.C) { c.Run("Disable "+disableKind, func(c *qt.C) {
b := newSitesBuilder(c, disableKind) b := newSitesBuilder(c, disableKind)
b.Build(BuildCfg{}) b.Build(BuildCfg{})
@ -219,21 +220,21 @@ title: Headless Local Lists Sub
b.Assert(home.OutputFormats(), qt.HasLen, 1) b.Assert(home.OutputFormats(), qt.HasLen, 1)
}) })
disableKind = kindSitemap disableKind = kinds.KindSitemap
c.Run("Disable "+disableKind, func(c *qt.C) { c.Run("Disable "+disableKind, func(c *qt.C) {
b := newSitesBuilder(c, disableKind) b := newSitesBuilder(c, disableKind)
b.Build(BuildCfg{}) b.Build(BuildCfg{})
b.Assert(b.CheckExists("public/sitemap.xml"), qt.Equals, false) b.Assert(b.CheckExists("public/sitemap.xml"), qt.Equals, false)
}) })
disableKind = kind404 disableKind = kinds.Kind404
c.Run("Disable "+disableKind, func(c *qt.C) { c.Run("Disable "+disableKind, func(c *qt.C) {
b := newSitesBuilder(c, disableKind) b := newSitesBuilder(c, disableKind)
b.Build(BuildCfg{}) b.Build(BuildCfg{})
b.Assert(b.CheckExists("public/404.html"), qt.Equals, false) b.Assert(b.CheckExists("public/404.html"), qt.Equals, false)
}) })
disableKind = kindRobotsTXT disableKind = kinds.KindRobotsTXT
c.Run("Disable "+disableKind, func(c *qt.C) { c.Run("Disable "+disableKind, func(c *qt.C) {
b := newSitesBuilder(c, disableKind) b := newSitesBuilder(c, disableKind)
b.WithTemplatesAdded("robots.txt", "myrobots") b.WithTemplatesAdded("robots.txt", "myrobots")

View file

@ -47,6 +47,7 @@ import (
"github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/lazy" "github.com/gohugoio/hugo/lazy"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/resources/page/pagemeta" "github.com/gohugoio/hugo/resources/page/pagemeta"
"github.com/gohugoio/hugo/tpl" "github.com/gohugoio/hugo/tpl"
@ -443,7 +444,7 @@ func (h *HugoSites) renderCrossSitesSitemap() error {
sitemapEnabled := false sitemapEnabled := false
for _, s := range h.Sites { for _, s := range h.Sites {
if s.conf.IsKindEnabled(kindSitemap) { if s.conf.IsKindEnabled(kinds.KindSitemap) {
sitemapEnabled = true sitemapEnabled = true
break break
} }
@ -474,7 +475,7 @@ func (h *HugoSites) renderCrossSitesRobotsTXT() error {
p, err := newPageStandalone(&pageMeta{ p, err := newPageStandalone(&pageMeta{
s: s, s: s,
kind: kindRobotsTXT, kind: kinds.KindRobotsTXT,
urlPaths: pagemeta.URLPath{ urlPaths: pagemeta.URLPath{
URL: "robots.txt", URL: "robots.txt",
}, },
@ -523,7 +524,7 @@ func (h *HugoSites) createPageCollections() error {
}) })
allRegularPages := newLazyPagesFactory(func() page.Pages { allRegularPages := newLazyPagesFactory(func() page.Pages {
return h.findPagesByKindIn(page.KindPage, allPages.get()) return h.findPagesByKindIn(kinds.KindPage, allPages.get())
}) })
for _, s := range h.Sites { for _, s := range h.Sites {

View file

@ -10,7 +10,7 @@ import (
qt "github.com/frankban/quicktest" qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/htesting" "github.com/gohugoio/hugo/htesting"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/kinds"
"github.com/fortytw2/leaktest" "github.com/fortytw2/leaktest"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
@ -182,12 +182,12 @@ p1 = "p1en"
c.Assert(len(sites), qt.Equals, 2) c.Assert(len(sites), qt.Equals, 2)
nnSite := sites[0] nnSite := sites[0]
nnHome := nnSite.getPage(page.KindHome) nnHome := nnSite.getPage(kinds.KindHome)
c.Assert(len(nnHome.AllTranslations()), qt.Equals, 2) c.Assert(len(nnHome.AllTranslations()), qt.Equals, 2)
c.Assert(len(nnHome.Translations()), qt.Equals, 1) c.Assert(len(nnHome.Translations()), qt.Equals, 1)
c.Assert(nnHome.IsTranslated(), qt.Equals, true) c.Assert(nnHome.IsTranslated(), qt.Equals, true)
enHome := sites[1].getPage(page.KindHome) enHome := sites[1].getPage(kinds.KindHome)
p1, err := enHome.Param("p1") p1, err := enHome.Param("p1")
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
@ -239,7 +239,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
c.Assert(gp2, qt.IsNil) c.Assert(gp2, qt.IsNil)
enSite := sites[0] enSite := sites[0]
enSiteHome := enSite.getPage(page.KindHome) enSiteHome := enSite.getPage(kinds.KindHome)
c.Assert(enSiteHome.IsTranslated(), qt.Equals, true) c.Assert(enSiteHome.IsTranslated(), qt.Equals, true)
c.Assert(enSite.language.Lang, qt.Equals, "en") c.Assert(enSite.language.Lang, qt.Equals, "en")
@ -300,10 +300,10 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
// isn't ideal in a multilingual setup. You want a way to get the current language version if available. // isn't ideal in a multilingual setup. You want a way to get the current language version if available.
// Now you can do lookups with translation base name to get that behaviour. // Now you can do lookups with translation base name to get that behaviour.
// Let us test all the regular page variants: // Let us test all the regular page variants:
getPageDoc1En := enSite.getPage(page.KindPage, filepath.ToSlash(doc1en.File().Path())) getPageDoc1En := enSite.getPage(kinds.KindPage, filepath.ToSlash(doc1en.File().Path()))
getPageDoc1EnBase := enSite.getPage(page.KindPage, "sect/doc1") getPageDoc1EnBase := enSite.getPage(kinds.KindPage, "sect/doc1")
getPageDoc1Fr := frSite.getPage(page.KindPage, filepath.ToSlash(doc1fr.File().Path())) getPageDoc1Fr := frSite.getPage(kinds.KindPage, filepath.ToSlash(doc1fr.File().Path()))
getPageDoc1FrBase := frSite.getPage(page.KindPage, "sect/doc1") getPageDoc1FrBase := frSite.getPage(kinds.KindPage, "sect/doc1")
c.Assert(getPageDoc1En, qt.Equals, doc1en) c.Assert(getPageDoc1En, qt.Equals, doc1en)
c.Assert(getPageDoc1Fr, qt.Equals, doc1fr) c.Assert(getPageDoc1Fr, qt.Equals, doc1fr)
c.Assert(getPageDoc1EnBase, qt.Equals, doc1en) c.Assert(getPageDoc1EnBase, qt.Equals, doc1en)
@ -321,7 +321,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
b.AssertFileContent("public/en/sect/doc1-slug/index.html", "Single", "Shortcode: Hello", "LingoDefault") b.AssertFileContent("public/en/sect/doc1-slug/index.html", "Single", "Shortcode: Hello", "LingoDefault")
// Check node translations // Check node translations
homeEn := enSite.getPage(page.KindHome) homeEn := enSite.getPage(kinds.KindHome)
c.Assert(homeEn, qt.Not(qt.IsNil)) c.Assert(homeEn, qt.Not(qt.IsNil))
c.Assert(len(homeEn.Translations()), qt.Equals, 3) c.Assert(len(homeEn.Translations()), qt.Equals, 3)
c.Assert(homeEn.Translations()[0].Language().Lang, qt.Equals, "fr") c.Assert(homeEn.Translations()[0].Language().Lang, qt.Equals, "fr")
@ -331,7 +331,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
c.Assert(homeEn.Translations()[2].Title(), qt.Equals, "På bokmål") c.Assert(homeEn.Translations()[2].Title(), qt.Equals, "På bokmål")
c.Assert(homeEn.Translations()[2].Language().LanguageName, qt.Equals, "Bokmål") c.Assert(homeEn.Translations()[2].Language().LanguageName, qt.Equals, "Bokmål")
sectFr := frSite.getPage(page.KindSection, "sect") sectFr := frSite.getPage(kinds.KindSection, "sect")
c.Assert(sectFr, qt.Not(qt.IsNil)) c.Assert(sectFr, qt.Not(qt.IsNil))
c.Assert(sectFr.Language().Lang, qt.Equals, "fr") c.Assert(sectFr.Language().Lang, qt.Equals, "fr")
@ -341,14 +341,14 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
nnSite := sites[2] nnSite := sites[2]
c.Assert(nnSite.language.Lang, qt.Equals, "nn") c.Assert(nnSite.language.Lang, qt.Equals, "nn")
taxNn := nnSite.getPage(page.KindTaxonomy, "lag") taxNn := nnSite.getPage(kinds.KindTaxonomy, "lag")
c.Assert(taxNn, qt.Not(qt.IsNil)) c.Assert(taxNn, qt.Not(qt.IsNil))
c.Assert(len(taxNn.Translations()), qt.Equals, 1) c.Assert(len(taxNn.Translations()), qt.Equals, 1)
c.Assert(taxNn.Translations()[0].Language().Lang, qt.Equals, "nb") c.Assert(taxNn.Translations()[0].Language().Lang, qt.Equals, "nb")
taxTermNn := nnSite.getPage(page.KindTerm, "lag", "sogndal") taxTermNn := nnSite.getPage(kinds.KindTerm, "lag", "sogndal")
c.Assert(taxTermNn, qt.Not(qt.IsNil)) c.Assert(taxTermNn, qt.Not(qt.IsNil))
c.Assert(nnSite.getPage(page.KindTerm, "LAG", "SOGNDAL"), qt.Equals, taxTermNn) c.Assert(nnSite.getPage(kinds.KindTerm, "LAG", "SOGNDAL"), qt.Equals, taxTermNn)
c.Assert(len(taxTermNn.Translations()), qt.Equals, 1) c.Assert(len(taxTermNn.Translations()), qt.Equals, 1)
c.Assert(taxTermNn.Translations()[0].Language().Lang, qt.Equals, "nb") c.Assert(taxTermNn.Translations()[0].Language().Lang, qt.Equals, "nb")
@ -379,19 +379,19 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
// Issue #3108 // Issue #3108
prevPage := enSite.RegularPages()[0].Prev() prevPage := enSite.RegularPages()[0].Prev()
c.Assert(prevPage, qt.Not(qt.IsNil)) c.Assert(prevPage, qt.Not(qt.IsNil))
c.Assert(prevPage.Kind(), qt.Equals, page.KindPage) c.Assert(prevPage.Kind(), qt.Equals, kinds.KindPage)
for { for {
if prevPage == nil { if prevPage == nil {
break break
} }
c.Assert(prevPage.Kind(), qt.Equals, page.KindPage) c.Assert(prevPage.Kind(), qt.Equals, kinds.KindPage)
prevPage = prevPage.Prev() prevPage = prevPage.Prev()
} }
// Check bundles // Check bundles
b.AssertFileContent("public/fr/bundles/b1/index.html", "RelPermalink: /blog/fr/bundles/b1/|") b.AssertFileContent("public/fr/bundles/b1/index.html", "RelPermalink: /blog/fr/bundles/b1/|")
bundleFr := frSite.getPage(page.KindPage, "bundles/b1/index.md") bundleFr := frSite.getPage(kinds.KindPage, "bundles/b1/index.md")
c.Assert(bundleFr, qt.Not(qt.IsNil)) c.Assert(bundleFr, qt.Not(qt.IsNil))
c.Assert(len(bundleFr.Resources()), qt.Equals, 1) c.Assert(len(bundleFr.Resources()), qt.Equals, 1)
logoFr := bundleFr.Resources().GetMatch("logo*") logoFr := bundleFr.Resources().GetMatch("logo*")
@ -401,7 +401,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
b.AssertFileContent("public/fr/bundles/b1/index.html", "Resources: image/png: /blog/fr/bundles/b1/logo.png") b.AssertFileContent("public/fr/bundles/b1/index.html", "Resources: image/png: /blog/fr/bundles/b1/logo.png")
b.AssertFileContent("public/fr/bundles/b1/logo.png", "PNG Data") b.AssertFileContent("public/fr/bundles/b1/logo.png", "PNG Data")
bundleEn := enSite.getPage(page.KindPage, "bundles/b1/index.en.md") bundleEn := enSite.getPage(kinds.KindPage, "bundles/b1/index.en.md")
c.Assert(bundleEn, qt.Not(qt.IsNil)) c.Assert(bundleEn, qt.Not(qt.IsNil))
b.AssertFileContent("public/en/bundles/b1/index.html", "RelPermalink: /blog/en/bundles/b1/|") b.AssertFileContent("public/en/bundles/b1/index.html", "RelPermalink: /blog/en/bundles/b1/|")
c.Assert(len(bundleEn.Resources()), qt.Equals, 1) c.Assert(len(bundleEn.Resources()), qt.Equals, 1)
@ -441,7 +441,7 @@ func TestMultiSitesRebuild(t *testing.T) {
b.AssertFileContent("public/fr/sect/doc1/index.html", "Single", "Shortcode: Bonjour") b.AssertFileContent("public/fr/sect/doc1/index.html", "Single", "Shortcode: Bonjour")
b.AssertFileContent("public/en/sect/doc1-slug/index.html", "Single", "Shortcode: Hello") b.AssertFileContent("public/en/sect/doc1-slug/index.html", "Single", "Shortcode: Hello")
homeEn := enSite.getPage(page.KindHome) homeEn := enSite.getPage(kinds.KindHome)
c.Assert(homeEn, qt.Not(qt.IsNil)) c.Assert(homeEn, qt.Not(qt.IsNil))
c.Assert(len(homeEn.Translations()), qt.Equals, 3) c.Assert(len(homeEn.Translations()), qt.Equals, 3)
@ -558,7 +558,7 @@ func TestMultiSitesRebuild(t *testing.T) {
docFr := readWorkingDir(t, fs, "public/fr/sect/doc1/index.html") docFr := readWorkingDir(t, fs, "public/fr/sect/doc1/index.html")
c.Assert(strings.Contains(docFr, "Salut"), qt.Equals, true) c.Assert(strings.Contains(docFr, "Salut"), qt.Equals, true)
homeEn := enSite.getPage(page.KindHome) homeEn := enSite.getPage(kinds.KindHome)
c.Assert(homeEn, qt.Not(qt.IsNil)) c.Assert(homeEn, qt.Not(qt.IsNil))
c.Assert(len(homeEn.Translations()), qt.Equals, 3) c.Assert(len(homeEn.Translations()), qt.Equals, 3)
c.Assert(homeEn.Translations()[0].Language().Lang, qt.Equals, "fr") c.Assert(homeEn.Translations()[0].Language().Lang, qt.Equals, "fr")

View file

@ -3,7 +3,7 @@ package hugolib
import ( import (
"testing" "testing"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/kinds"
qt "github.com/frankban/quicktest" qt "github.com/frankban/quicktest"
) )
@ -58,7 +58,7 @@ languageName = "Nynorsk"
s1 := b.H.Sites[0] s1 := b.H.Sites[0]
s1h := s1.getPage(page.KindHome) s1h := s1.getPage(kinds.KindHome)
c.Assert(s1h.IsTranslated(), qt.Equals, true) c.Assert(s1h.IsTranslated(), qt.Equals, true)
c.Assert(len(s1h.Translations()), qt.Equals, 2) c.Assert(len(s1h.Translations()), qt.Equals, 2)
c.Assert(s1h.Permalink(), qt.Equals, "https://example.com/docs/") c.Assert(s1h.Permalink(), qt.Equals, "https://example.com/docs/")
@ -69,7 +69,7 @@ languageName = "Nynorsk"
// For multihost, we never want any content in the root. // For multihost, we never want any content in the root.
// //
// check url in front matter: // check url in front matter:
pageWithURLInFrontMatter := s1.getPage(page.KindPage, "sect/doc3.en.md") pageWithURLInFrontMatter := s1.getPage(kinds.KindPage, "sect/doc3.en.md")
c.Assert(pageWithURLInFrontMatter, qt.Not(qt.IsNil)) c.Assert(pageWithURLInFrontMatter, qt.Not(qt.IsNil))
c.Assert(pageWithURLInFrontMatter.RelPermalink(), qt.Equals, "/docs/superbob/") c.Assert(pageWithURLInFrontMatter.RelPermalink(), qt.Equals, "/docs/superbob/")
b.AssertFileContent("public/en/superbob/index.html", "doc3|Hello|en") b.AssertFileContent("public/en/superbob/index.html", "doc3|Hello|en")
@ -86,7 +86,7 @@ languageName = "Nynorsk"
s2 := b.H.Sites[1] s2 := b.H.Sites[1]
s2h := s2.getPage(page.KindHome) s2h := s2.getPage(kinds.KindHome)
c.Assert(s2h.Permalink(), qt.Equals, "https://example.fr/") c.Assert(s2h.Permalink(), qt.Equals, "https://example.fr/")
// See https://github.com/gohugoio/hugo/issues/10912 // See https://github.com/gohugoio/hugo/issues/10912
@ -104,7 +104,7 @@ languageName = "Nynorsk"
// Check bundles // Check bundles
bundleEn := s1.getPage(page.KindPage, "bundles/b1/index.en.md") bundleEn := s1.getPage(kinds.KindPage, "bundles/b1/index.en.md")
c.Assert(bundleEn, qt.Not(qt.IsNil)) c.Assert(bundleEn, qt.Not(qt.IsNil))
c.Assert(bundleEn.RelPermalink(), qt.Equals, "/docs/bundles/b1/") c.Assert(bundleEn.RelPermalink(), qt.Equals, "/docs/bundles/b1/")
c.Assert(len(bundleEn.Resources()), qt.Equals, 1) c.Assert(len(bundleEn.Resources()), qt.Equals, 1)
@ -112,7 +112,7 @@ languageName = "Nynorsk"
b.AssertFileContent("public/en/bundles/b1/logo.png", "PNG Data") b.AssertFileContent("public/en/bundles/b1/logo.png", "PNG Data")
b.AssertFileContent("public/en/bundles/b1/index.html", " image/png: /docs/bundles/b1/logo.png") b.AssertFileContent("public/en/bundles/b1/index.html", " image/png: /docs/bundles/b1/logo.png")
bundleFr := s2.getPage(page.KindPage, "bundles/b1/index.md") bundleFr := s2.getPage(kinds.KindPage, "bundles/b1/index.md")
c.Assert(bundleFr, qt.Not(qt.IsNil)) c.Assert(bundleFr, qt.Not(qt.IsNil))
c.Assert(bundleFr.RelPermalink(), qt.Equals, "/bundles/b1/") c.Assert(bundleFr.RelPermalink(), qt.Equals, "/bundles/b1/")
c.Assert(len(bundleFr.Resources()), qt.Equals, 1) c.Assert(len(bundleFr.Resources()), qt.Equals, 1)

View file

@ -20,10 +20,9 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/spf13/cast" "github.com/spf13/cast"
"github.com/gohugoio/hugo/resources/page"
qt "github.com/frankban/quicktest" qt "github.com/frankban/quicktest"
) )
@ -312,7 +311,7 @@ Content.
b.AssertFileContent("public/sv/sect/mybundle/logo.png", "PNG Data") b.AssertFileContent("public/sv/sect/mybundle/logo.png", "PNG Data")
b.AssertFileContent("public/nn/sect/mybundle/logo.png", "PNG Data") b.AssertFileContent("public/nn/sect/mybundle/logo.png", "PNG Data")
nnSect := nnSite.getPage(page.KindSection, "sect") nnSect := nnSite.getPage(kinds.KindSection, "sect")
c.Assert(nnSect, qt.Not(qt.IsNil)) c.Assert(nnSect, qt.Not(qt.IsNil))
c.Assert(len(nnSect.Pages()), qt.Equals, 12) c.Assert(len(nnSect.Pages()), qt.Equals, 12)
nnHome := nnSite.Home() nnHome := nnSite.Home()

View file

@ -49,6 +49,7 @@ import (
"github.com/gohugoio/hugo/common/collections" "github.com/gohugoio/hugo/common/collections"
"github.com/gohugoio/hugo/common/text" "github.com/gohugoio/hugo/common/text"
"github.com/gohugoio/hugo/resources" "github.com/gohugoio/hugo/resources"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/resources/resource" "github.com/gohugoio/hugo/resources/resource"
) )
@ -249,7 +250,7 @@ func (p *pageState) RegularPagesRecursive() page.Pages {
p.regularPagesRecursiveInit.Do(func() { p.regularPagesRecursiveInit.Do(func() {
var pages page.Pages var pages page.Pages
switch p.Kind() { switch p.Kind() {
case page.KindSection: case kinds.KindSection:
pages = p.getPagesRecursive() pages = p.getPagesRecursive()
default: default:
pages = p.RegularPages() pages = p.RegularPages()
@ -268,10 +269,10 @@ func (p *pageState) RegularPages() page.Pages {
var pages page.Pages var pages page.Pages
switch p.Kind() { switch p.Kind() {
case page.KindPage: case kinds.KindPage:
case page.KindSection, page.KindHome, page.KindTaxonomy: case kinds.KindSection, kinds.KindHome, kinds.KindTaxonomy:
pages = p.getPages() pages = p.getPages()
case page.KindTerm: case kinds.KindTerm:
all := p.Pages() all := p.Pages()
for _, p := range all { for _, p := range all {
if p.IsPage() { if p.IsPage() {
@ -293,15 +294,15 @@ func (p *pageState) Pages() page.Pages {
var pages page.Pages var pages page.Pages
switch p.Kind() { switch p.Kind() {
case page.KindPage: case kinds.KindPage:
case page.KindSection, page.KindHome: case kinds.KindSection, kinds.KindHome:
pages = p.getPagesAndSections() pages = p.getPagesAndSections()
case page.KindTerm: case kinds.KindTerm:
b := p.treeRef.n b := p.treeRef.n
viewInfo := b.viewInfo viewInfo := b.viewInfo
taxonomy := p.s.Taxonomies()[viewInfo.name.plural].Get(viewInfo.termKey) taxonomy := p.s.Taxonomies()[viewInfo.name.plural].Get(viewInfo.termKey)
pages = taxonomy.Pages() pages = taxonomy.Pages()
case page.KindTaxonomy: case kinds.KindTaxonomy:
pages = p.bucket.getTaxonomies() pages = p.bucket.getTaxonomies()
default: default:
pages = p.s.Pages() pages = p.s.Pages()
@ -439,11 +440,11 @@ func (p *pageState) getLayoutDescriptor() layouts.LayoutDescriptor {
sections := p.SectionsEntries() sections := p.SectionsEntries()
switch p.Kind() { switch p.Kind() {
case page.KindSection: case kinds.KindSection:
if len(sections) > 0 { if len(sections) > 0 {
section = sections[0] section = sections[0]
} }
case page.KindTaxonomy, page.KindTerm: case kinds.KindTaxonomy, kinds.KindTerm:
b := p.getTreeRef().n b := p.getTreeRef().n
section = b.viewInfo.name.singular section = b.viewInfo.name.singular
default: default:

View file

@ -16,6 +16,7 @@ package hugolib
import ( import (
"sync" "sync"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
) )
@ -30,12 +31,12 @@ func (p *pageData) Data() any {
p.dataInit.Do(func() { p.dataInit.Do(func() {
p.data = make(page.Data) p.data = make(page.Data)
if p.Kind() == page.KindPage { if p.Kind() == kinds.KindPage {
return return
} }
switch p.Kind() { switch p.Kind() {
case page.KindTerm: case kinds.KindTerm:
b := p.treeRef.n b := p.treeRef.n
name := b.viewInfo.name name := b.viewInfo.name
termKey := b.viewInfo.termKey termKey := b.viewInfo.termKey
@ -46,7 +47,7 @@ func (p *pageData) Data() any {
p.data["Singular"] = name.singular p.data["Singular"] = name.singular
p.data["Plural"] = name.plural p.data["Plural"] = name.plural
p.data["Term"] = b.viewInfo.term() p.data["Term"] = b.viewInfo.term()
case page.KindTaxonomy: case kinds.KindTaxonomy:
b := p.treeRef.n b := p.treeRef.n
name := b.viewInfo.name name := b.viewInfo.name

View file

@ -40,6 +40,7 @@ import (
"github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/output" "github.com/gohugoio/hugo/output"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/resources/page/pagemeta" "github.com/gohugoio/hugo/resources/page/pagemeta"
"github.com/gohugoio/hugo/resources/resource" "github.com/gohugoio/hugo/resources/resource"
@ -164,7 +165,7 @@ func (p *pageMeta) File() source.File {
} }
func (p *pageMeta) IsHome() bool { func (p *pageMeta) IsHome() bool {
return p.Kind() == page.KindHome return p.Kind() == kinds.KindHome
} }
func (p *pageMeta) Keywords() []string { func (p *pageMeta) Keywords() []string {
@ -199,7 +200,7 @@ func (p *pageMeta) IsNode() bool {
} }
func (p *pageMeta) IsPage() bool { func (p *pageMeta) IsPage() bool {
return p.Kind() == page.KindPage return p.Kind() == kinds.KindPage
} }
// Param is a convenience method to do lookups in Page's and Site's Params map, // Param is a convenience method to do lookups in Page's and Site's Params map,
@ -251,7 +252,7 @@ func (p *pageMeta) RelatedKeywords(cfg related.IndexConfig) ([]related.Keyword,
} }
func (p *pageMeta) IsSection() bool { func (p *pageMeta) IsSection() bool {
return p.Kind() == page.KindSection return p.Kind() == kinds.KindSection
} }
func (p *pageMeta) Section() string { func (p *pageMeta) Section() string {
@ -680,9 +681,9 @@ func (p *pageMeta) applyDefaultValues(n *contentNode) error {
if p.title == "" && p.f.IsZero() { if p.title == "" && p.f.IsZero() {
switch p.Kind() { switch p.Kind() {
case page.KindHome: case kinds.KindHome:
p.title = p.s.Title() p.title = p.s.Title()
case page.KindSection: case kinds.KindSection:
var sectionName string var sectionName string
if n != nil { if n != nil {
sectionName = n.rootSection() sectionName = n.rootSection()
@ -696,13 +697,13 @@ func (p *pageMeta) applyDefaultValues(n *contentNode) error {
} else { } else {
p.title = sectionName p.title = sectionName
} }
case page.KindTerm: case kinds.KindTerm:
// TODO(bep) improve // TODO(bep) improve
key := p.sections[len(p.sections)-1] key := p.sections[len(p.sections)-1]
p.title = strings.Replace(p.s.conf.C.CreateTitle(key), "-", " ", -1) p.title = strings.Replace(p.s.conf.C.CreateTitle(key), "-", " ", -1)
case page.KindTaxonomy: case kinds.KindTaxonomy:
p.title = p.s.conf.C.CreateTitle(p.sections[0]) p.title = p.s.conf.C.CreateTitle(p.sections[0])
case kind404: case kinds.Kind404:
p.title = "404 Page not found" p.title = "404 Page not found"
} }

View file

@ -17,6 +17,7 @@ import (
"sync" "sync"
"github.com/gohugoio/hugo/common/herrors" "github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
) )
@ -86,12 +87,12 @@ func (p *pagePaginator) Paginator(options ...any) (*page.Pager, error) {
var pages page.Pages var pages page.Pages
switch p.source.Kind() { switch p.source.Kind() {
case page.KindHome: case kinds.KindHome:
// From Hugo 0.57 we made home.Pages() work like any other // From Hugo 0.57 we made home.Pages() work like any other
// section. To avoid the default paginators for the home page // section. To avoid the default paginators for the home page
// changing in the wild, we make this a special case. // changing in the wild, we make this a special case.
pages = p.source.s.RegularPages() pages = p.source.s.RegularPages()
case page.KindTerm, page.KindTaxonomy: case kinds.KindTerm, kinds.KindTaxonomy:
pages = p.source.Pages() pages = p.source.Pages()
default: default:
pages = p.source.RegularPages() pages = p.source.RegularPages()

View file

@ -20,6 +20,7 @@ import (
"github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugofs/files" "github.com/gohugoio/hugo/hugofs/files"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
) )
@ -125,7 +126,7 @@ func createTargetPathDescriptor(s *Site, p page.Page, pm *pageMeta) (page.Target
baseName = contentBaseName baseName = contentBaseName
} }
alwaysInSubDir := p.Kind() == kindSitemap alwaysInSubDir := p.Kind() == kinds.KindSitemap
desc := page.TargetPathDescriptor{ desc := page.TargetPathDescriptor{
PathSpec: d.PathSpec, PathSpec: d.PathSpec,

View file

@ -18,6 +18,7 @@ import (
"strings" "strings"
"github.com/gohugoio/hugo/common/types" "github.com/gohugoio/hugo/common/types"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
) )
@ -166,7 +167,7 @@ func (pt pageTree) Parent() page.Page {
tree := p.getTreeRef() tree := p.getTreeRef()
if tree == nil || pt.p.Kind() == page.KindTaxonomy { if tree == nil || pt.p.Kind() == kinds.KindTaxonomy {
return pt.p.s.home return pt.p.s.home
} }

View file

@ -13,40 +13,6 @@
package hugolib package hugolib
import (
"strings"
"github.com/gohugoio/hugo/resources/page"
)
// This is all the kinds we can expect to find in .Site.Pages.
var allKindsInPages = []string{page.KindPage, page.KindHome, page.KindSection, page.KindTerm, page.KindTaxonomy}
const ( const (
// Temporary state.
kindUnknown = "unknown"
// The following are (currently) temporary nodes,
// i.e. nodes we create just to render in isolation.
kindRSS = "rss"
kindSitemap = "sitemap"
kindRobotsTXT = "robotstxt"
kind404 = "404"
pageResourceType = "page" pageResourceType = "page"
) )
var kindMap = map[string]string{
strings.ToLower(kindRSS): kindRSS,
strings.ToLower(kindSitemap): kindSitemap,
strings.ToLower(kindRobotsTXT): kindRobotsTXT,
strings.ToLower(kind404): kind404,
}
func getKind(s string) string {
if pkind := page.GetKind(s); pkind != "" {
return pkind
}
return kindMap[strings.ToLower(s)]
}

View file

@ -34,6 +34,7 @@ import (
"github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/htesting" "github.com/gohugoio/hugo/htesting"
@ -104,7 +105,7 @@ func TestPageBundlerSiteRegular(t *testing.T) {
c.Assert(len(s.RegularPages()), qt.Equals, 8) c.Assert(len(s.RegularPages()), qt.Equals, 8)
singlePage := s.getPage(page.KindPage, "a/1.md") singlePage := s.getPage(kinds.KindPage, "a/1.md")
c.Assert(singlePage.BundleType(), qt.Equals, files.ContentClass("")) c.Assert(singlePage.BundleType(), qt.Equals, files.ContentClass(""))
c.Assert(singlePage, qt.Not(qt.IsNil)) c.Assert(singlePage, qt.Not(qt.IsNil))
@ -150,18 +151,18 @@ func TestPageBundlerSiteRegular(t *testing.T) {
// This should be just copied to destination. // This should be just copied to destination.
b.AssertFileContent(filepath.FromSlash("public/assets/pic1.png"), "content") b.AssertFileContent(filepath.FromSlash("public/assets/pic1.png"), "content")
leafBundle1 := s.getPage(page.KindPage, "b/my-bundle/index.md") leafBundle1 := s.getPage(kinds.KindPage, "b/my-bundle/index.md")
c.Assert(leafBundle1, qt.Not(qt.IsNil)) c.Assert(leafBundle1, qt.Not(qt.IsNil))
c.Assert(leafBundle1.BundleType(), qt.Equals, files.ContentClassLeaf) c.Assert(leafBundle1.BundleType(), qt.Equals, files.ContentClassLeaf)
c.Assert(leafBundle1.Section(), qt.Equals, "b") c.Assert(leafBundle1.Section(), qt.Equals, "b")
sectionB := s.getPage(page.KindSection, "b") sectionB := s.getPage(kinds.KindSection, "b")
c.Assert(sectionB, qt.Not(qt.IsNil)) c.Assert(sectionB, qt.Not(qt.IsNil))
home := s.Home() home := s.Home()
c.Assert(home.BundleType(), qt.Equals, files.ContentClassBranch) c.Assert(home.BundleType(), qt.Equals, files.ContentClassBranch)
// This is a root bundle and should live in the "home section" // This is a root bundle and should live in the "home section"
// See https://github.com/gohugoio/hugo/issues/4332 // See https://github.com/gohugoio/hugo/issues/4332
rootBundle := s.getPage(page.KindPage, "root") rootBundle := s.getPage(kinds.KindPage, "root")
c.Assert(rootBundle, qt.Not(qt.IsNil)) c.Assert(rootBundle, qt.Not(qt.IsNil))
c.Assert(rootBundle.Parent().IsHome(), qt.Equals, true) c.Assert(rootBundle.Parent().IsHome(), qt.Equals, true)
if !ugly { if !ugly {
@ -169,9 +170,9 @@ func TestPageBundlerSiteRegular(t *testing.T) {
b.AssertFileContent(filepath.FromSlash("public/cpath/root/cindex.html"), "Single RelPermalink: "+relURLBase+"/cpath/root/") b.AssertFileContent(filepath.FromSlash("public/cpath/root/cindex.html"), "Single RelPermalink: "+relURLBase+"/cpath/root/")
} }
leafBundle2 := s.getPage(page.KindPage, "a/b/index.md") leafBundle2 := s.getPage(kinds.KindPage, "a/b/index.md")
c.Assert(leafBundle2, qt.Not(qt.IsNil)) c.Assert(leafBundle2, qt.Not(qt.IsNil))
unicodeBundle := s.getPage(page.KindPage, "c/bundle/index.md") unicodeBundle := s.getPage(kinds.KindPage, "c/bundle/index.md")
c.Assert(unicodeBundle, qt.Not(qt.IsNil)) c.Assert(unicodeBundle, qt.Not(qt.IsNil))
pageResources := leafBundle1.Resources().ByType(pageResourceType) pageResources := leafBundle1.Resources().ByType(pageResourceType)
@ -302,7 +303,7 @@ func TestPageBundlerSiteMultilingual(t *testing.T) {
c.Assert(len(s.AllPages()), qt.Equals, 31) c.Assert(len(s.AllPages()), qt.Equals, 31)
bundleWithSubPath := s.getPage(page.KindPage, "lb/index") bundleWithSubPath := s.getPage(kinds.KindPage, "lb/index")
c.Assert(bundleWithSubPath, qt.Not(qt.IsNil)) c.Assert(bundleWithSubPath, qt.Not(qt.IsNil))
// See https://github.com/gohugoio/hugo/issues/4312 // See https://github.com/gohugoio/hugo/issues/4312
@ -316,22 +317,22 @@ func TestPageBundlerSiteMultilingual(t *testing.T) {
// and probably also just b (aka "my-bundle") // and probably also just b (aka "my-bundle")
// These may also be translated, so we also need to test that. // These may also be translated, so we also need to test that.
// "bf", "my-bf-bundle", "index.md + nn // "bf", "my-bf-bundle", "index.md + nn
bfBundle := s.getPage(page.KindPage, "bf/my-bf-bundle/index") bfBundle := s.getPage(kinds.KindPage, "bf/my-bf-bundle/index")
c.Assert(bfBundle, qt.Not(qt.IsNil)) c.Assert(bfBundle, qt.Not(qt.IsNil))
c.Assert(bfBundle.Language().Lang, qt.Equals, "en") c.Assert(bfBundle.Language().Lang, qt.Equals, "en")
c.Assert(s.getPage(page.KindPage, "bf/my-bf-bundle/index.md"), qt.Equals, bfBundle) c.Assert(s.getPage(kinds.KindPage, "bf/my-bf-bundle/index.md"), qt.Equals, bfBundle)
c.Assert(s.getPage(page.KindPage, "bf/my-bf-bundle"), qt.Equals, bfBundle) c.Assert(s.getPage(kinds.KindPage, "bf/my-bf-bundle"), qt.Equals, bfBundle)
c.Assert(s.getPage(page.KindPage, "my-bf-bundle"), qt.Equals, bfBundle) c.Assert(s.getPage(kinds.KindPage, "my-bf-bundle"), qt.Equals, bfBundle)
nnSite := sites.Sites[1] nnSite := sites.Sites[1]
c.Assert(len(nnSite.RegularPages()), qt.Equals, 7) c.Assert(len(nnSite.RegularPages()), qt.Equals, 7)
bfBundleNN := nnSite.getPage(page.KindPage, "bf/my-bf-bundle/index") bfBundleNN := nnSite.getPage(kinds.KindPage, "bf/my-bf-bundle/index")
c.Assert(bfBundleNN, qt.Not(qt.IsNil)) c.Assert(bfBundleNN, qt.Not(qt.IsNil))
c.Assert(bfBundleNN.Language().Lang, qt.Equals, "nn") c.Assert(bfBundleNN.Language().Lang, qt.Equals, "nn")
c.Assert(nnSite.getPage(page.KindPage, "bf/my-bf-bundle/index.nn.md"), qt.Equals, bfBundleNN) c.Assert(nnSite.getPage(kinds.KindPage, "bf/my-bf-bundle/index.nn.md"), qt.Equals, bfBundleNN)
c.Assert(nnSite.getPage(page.KindPage, "bf/my-bf-bundle"), qt.Equals, bfBundleNN) c.Assert(nnSite.getPage(kinds.KindPage, "bf/my-bf-bundle"), qt.Equals, bfBundleNN)
c.Assert(nnSite.getPage(page.KindPage, "my-bf-bundle"), qt.Equals, bfBundleNN) c.Assert(nnSite.getPage(kinds.KindPage, "my-bf-bundle"), qt.Equals, bfBundleNN)
// See https://github.com/gohugoio/hugo/issues/4295 // See https://github.com/gohugoio/hugo/issues/4295
// Every resource should have its Name prefixed with its base folder. // Every resource should have its Name prefixed with its base folder.
@ -483,7 +484,7 @@ TheContent.
s := b.H.Sites[0] s := b.H.Sites[0]
c.Assert(len(s.RegularPages()), qt.Equals, 7) c.Assert(len(s.RegularPages()), qt.Equals, 7)
a1Bundle := s.getPage(page.KindPage, "symbolic2/a1/index.md") a1Bundle := s.getPage(kinds.KindPage, "symbolic2/a1/index.md")
c.Assert(a1Bundle, qt.Not(qt.IsNil)) c.Assert(a1Bundle, qt.Not(qt.IsNil))
c.Assert(len(a1Bundle.Resources()), qt.Equals, 2) c.Assert(len(a1Bundle.Resources()), qt.Equals, 2)
c.Assert(len(a1Bundle.Resources().ByType(pageResourceType)), qt.Equals, 1) c.Assert(len(a1Bundle.Resources().ByType(pageResourceType)), qt.Equals, 1)
@ -543,10 +544,10 @@ HEADLESS {{< myShort >}}
c.Assert(len(s.RegularPages()), qt.Equals, 1) c.Assert(len(s.RegularPages()), qt.Equals, 1)
regular := s.getPage(page.KindPage, "a/index") regular := s.getPage(kinds.KindPage, "a/index")
c.Assert(regular.RelPermalink(), qt.Equals, "/s1/") c.Assert(regular.RelPermalink(), qt.Equals, "/s1/")
headless := s.getPage(page.KindPage, "b/index") headless := s.getPage(kinds.KindPage, "b/index")
c.Assert(headless, qt.Not(qt.IsNil)) c.Assert(headless, qt.Not(qt.IsNil))
c.Assert(headless.Title(), qt.Equals, "Headless Bundle in Topless Bar") c.Assert(headless.Title(), qt.Equals, "Headless Bundle in Topless Bar")
c.Assert(headless.RelPermalink(), qt.Equals, "") c.Assert(headless.RelPermalink(), qt.Equals, "")

View file

@ -26,6 +26,7 @@ import (
"github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
) )
@ -92,7 +93,7 @@ func newPageCollections(m *pageMap) *PageCollections {
}) })
c.regularPages = newLazyPagesFactory(func() page.Pages { c.regularPages = newLazyPagesFactory(func() page.Pages {
return c.findPagesByKindIn(page.KindPage, c.pages.get()) return c.findPagesByKindIn(kinds.KindPage, c.pages.get())
}) })
return c return c
@ -120,10 +121,10 @@ func (c *PageCollections) getPageOldVersion(ref ...string) (page.Page, error) {
return nil, fmt.Errorf(`too many arguments to .Site.GetPage: %v. Use lookups on the form {{ .Site.GetPage "/posts/mypage-md" }}`, ref) return nil, fmt.Errorf(`too many arguments to .Site.GetPage: %v. Use lookups on the form {{ .Site.GetPage "/posts/mypage-md" }}`, ref)
} }
if len(refs) == 0 || refs[0] == page.KindHome { if len(refs) == 0 || refs[0] == kinds.KindHome {
key = "/" key = "/"
} else if len(refs) == 1 { } else if len(refs) == 1 {
if len(ref) == 2 && refs[0] == page.KindSection { if len(ref) == 2 && refs[0] == kinds.KindSection {
// This is an old style reference to the "Home Page section". // This is an old style reference to the "Home Page section".
// Typically fetched via {{ .Site.GetPage "section" .Section }} // Typically fetched via {{ .Site.GetPage "section" .Section }}
// See https://github.com/gohugoio/hugo/issues/4989 // See https://github.com/gohugoio/hugo/issues/4989

View file

@ -22,6 +22,7 @@ import (
"time" "time"
qt "github.com/frankban/quicktest" qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/deps"
@ -231,72 +232,72 @@ func TestGetPage(t *testing.T) {
tests := []getPageTest{ tests := []getPageTest{
// legacy content root relative paths // legacy content root relative paths
{"Root relative, no slash, home", page.KindHome, nil, []string{""}, "home page"}, {"Root relative, no slash, home", kinds.KindHome, nil, []string{""}, "home page"},
{"Root relative, no slash, root page", page.KindPage, nil, []string{"about.md", "ABOUT.md"}, "about page"}, {"Root relative, no slash, root page", kinds.KindPage, nil, []string{"about.md", "ABOUT.md"}, "about page"},
{"Root relative, no slash, section", page.KindSection, nil, []string{"sect3"}, "section 3"}, {"Root relative, no slash, section", kinds.KindSection, nil, []string{"sect3"}, "section 3"},
{"Root relative, no slash, section page", page.KindPage, nil, []string{"sect3/page1.md"}, "Title3_1"}, {"Root relative, no slash, section page", kinds.KindPage, nil, []string{"sect3/page1.md"}, "Title3_1"},
{"Root relative, no slash, sub section", page.KindSection, nil, []string{"sect3/sect7"}, "another sect7"}, {"Root relative, no slash, sub section", kinds.KindSection, nil, []string{"sect3/sect7"}, "another sect7"},
{"Root relative, no slash, nested page", page.KindPage, nil, []string{"sect3/subsect/deep.md"}, "deep page"}, {"Root relative, no slash, nested page", kinds.KindPage, nil, []string{"sect3/subsect/deep.md"}, "deep page"},
{"Root relative, no slash, OS slashes", page.KindPage, nil, []string{filepath.FromSlash("sect5/page3.md")}, "Title5_3"}, {"Root relative, no slash, OS slashes", kinds.KindPage, nil, []string{filepath.FromSlash("sect5/page3.md")}, "Title5_3"},
{"Short ref, unique", page.KindPage, nil, []string{"unique.md", "unique"}, "UniqueBase"}, {"Short ref, unique", kinds.KindPage, nil, []string{"unique.md", "unique"}, "UniqueBase"},
{"Short ref, unique, upper case", page.KindPage, nil, []string{"Unique2.md", "unique2.md", "unique2"}, "UniqueBase2"}, {"Short ref, unique, upper case", kinds.KindPage, nil, []string{"Unique2.md", "unique2.md", "unique2"}, "UniqueBase2"},
{"Short ref, ambiguous", "Ambiguous", nil, []string{"page1.md"}, ""}, {"Short ref, ambiguous", "Ambiguous", nil, []string{"page1.md"}, ""},
// ISSUE: This is an ambiguous ref, but because we have to support the legacy // ISSUE: This is an ambiguous ref, but because we have to support the legacy
// content root relative paths without a leading slash, the lookup // content root relative paths without a leading slash, the lookup
// returns /sect7. This undermines ambiguity detection, but we have no choice. // returns /sect7. This undermines ambiguity detection, but we have no choice.
//{"Ambiguous", nil, []string{"sect7"}, ""}, //{"Ambiguous", nil, []string{"sect7"}, ""},
{"Section, ambiguous", page.KindSection, nil, []string{"sect7"}, "Sect7s"}, {"Section, ambiguous", kinds.KindSection, nil, []string{"sect7"}, "Sect7s"},
{"Absolute, home", page.KindHome, nil, []string{"/", ""}, "home page"}, {"Absolute, home", kinds.KindHome, nil, []string{"/", ""}, "home page"},
{"Absolute, page", page.KindPage, nil, []string{"/about.md", "/about"}, "about page"}, {"Absolute, page", kinds.KindPage, nil, []string{"/about.md", "/about"}, "about page"},
{"Absolute, sect", page.KindSection, nil, []string{"/sect3"}, "section 3"}, {"Absolute, sect", kinds.KindSection, nil, []string{"/sect3"}, "section 3"},
{"Absolute, page in subsection", page.KindPage, nil, []string{"/sect3/page1.md", "/Sect3/Page1.md"}, "Title3_1"}, {"Absolute, page in subsection", kinds.KindPage, nil, []string{"/sect3/page1.md", "/Sect3/Page1.md"}, "Title3_1"},
{"Absolute, section, subsection with same name", page.KindSection, nil, []string{"/sect3/sect7"}, "another sect7"}, {"Absolute, section, subsection with same name", kinds.KindSection, nil, []string{"/sect3/sect7"}, "another sect7"},
{"Absolute, page, deep", page.KindPage, nil, []string{"/sect3/subsect/deep.md"}, "deep page"}, {"Absolute, page, deep", kinds.KindPage, nil, []string{"/sect3/subsect/deep.md"}, "deep page"},
{"Absolute, page, OS slashes", page.KindPage, nil, []string{filepath.FromSlash("/sect5/page3.md")}, "Title5_3"}, // test OS-specific path {"Absolute, page, OS slashes", kinds.KindPage, nil, []string{filepath.FromSlash("/sect5/page3.md")}, "Title5_3"}, // test OS-specific path
{"Absolute, unique", page.KindPage, nil, []string{"/sect3/unique.md"}, "UniqueBase"}, {"Absolute, unique", kinds.KindPage, nil, []string{"/sect3/unique.md"}, "UniqueBase"},
{"Absolute, unique, case", page.KindPage, nil, []string{"/sect3/Unique2.md", "/sect3/unique2.md", "/sect3/unique2", "/sect3/Unique2"}, "UniqueBase2"}, {"Absolute, unique, case", kinds.KindPage, nil, []string{"/sect3/Unique2.md", "/sect3/unique2.md", "/sect3/unique2", "/sect3/Unique2"}, "UniqueBase2"},
// next test depends on this page existing // next test depends on this page existing
// {"NoPage", nil, []string{"/unique.md"}, ""}, // ISSUE #4969: this is resolving to /sect3/unique.md // {"NoPage", nil, []string{"/unique.md"}, ""}, // ISSUE #4969: this is resolving to /sect3/unique.md
{"Absolute, missing page", "NoPage", nil, []string{"/missing-page.md"}, ""}, {"Absolute, missing page", "NoPage", nil, []string{"/missing-page.md"}, ""},
{"Absolute, missing section", "NoPage", nil, []string{"/missing-section"}, ""}, {"Absolute, missing section", "NoPage", nil, []string{"/missing-section"}, ""},
// relative paths // relative paths
{"Dot relative, home", page.KindHome, sec3, []string{".."}, "home page"}, {"Dot relative, home", kinds.KindHome, sec3, []string{".."}, "home page"},
{"Dot relative, home, slash", page.KindHome, sec3, []string{"../"}, "home page"}, {"Dot relative, home, slash", kinds.KindHome, sec3, []string{"../"}, "home page"},
{"Dot relative about", page.KindPage, sec3, []string{"../about.md"}, "about page"}, {"Dot relative about", kinds.KindPage, sec3, []string{"../about.md"}, "about page"},
{"Dot", page.KindSection, sec3, []string{"."}, "section 3"}, {"Dot", kinds.KindSection, sec3, []string{"."}, "section 3"},
{"Dot slash", page.KindSection, sec3, []string{"./"}, "section 3"}, {"Dot slash", kinds.KindSection, sec3, []string{"./"}, "section 3"},
{"Page relative, no dot", page.KindPage, sec3, []string{"page1.md"}, "Title3_1"}, {"Page relative, no dot", kinds.KindPage, sec3, []string{"page1.md"}, "Title3_1"},
{"Page relative, dot", page.KindPage, sec3, []string{"./page1.md"}, "Title3_1"}, {"Page relative, dot", kinds.KindPage, sec3, []string{"./page1.md"}, "Title3_1"},
{"Up and down another section", page.KindPage, sec3, []string{"../sect4/page2.md"}, "Title4_2"}, {"Up and down another section", kinds.KindPage, sec3, []string{"../sect4/page2.md"}, "Title4_2"},
{"Rel sect7", page.KindSection, sec3, []string{"sect7"}, "another sect7"}, {"Rel sect7", kinds.KindSection, sec3, []string{"sect7"}, "another sect7"},
{"Rel sect7 dot", page.KindSection, sec3, []string{"./sect7"}, "another sect7"}, {"Rel sect7 dot", kinds.KindSection, sec3, []string{"./sect7"}, "another sect7"},
{"Dot deep", page.KindPage, sec3, []string{"./subsect/deep.md"}, "deep page"}, {"Dot deep", kinds.KindPage, sec3, []string{"./subsect/deep.md"}, "deep page"},
{"Dot dot inner", page.KindPage, sec3, []string{"./subsect/../../sect7/page9.md"}, "Title7_9"}, {"Dot dot inner", kinds.KindPage, sec3, []string{"./subsect/../../sect7/page9.md"}, "Title7_9"},
{"Dot OS slash", page.KindPage, sec3, []string{filepath.FromSlash("../sect5/page3.md")}, "Title5_3"}, // test OS-specific path {"Dot OS slash", kinds.KindPage, sec3, []string{filepath.FromSlash("../sect5/page3.md")}, "Title5_3"}, // test OS-specific path
{"Dot unique", page.KindPage, sec3, []string{"./unique.md"}, "UniqueBase"}, {"Dot unique", kinds.KindPage, sec3, []string{"./unique.md"}, "UniqueBase"},
{"Dot sect", "NoPage", sec3, []string{"./sect2"}, ""}, {"Dot sect", "NoPage", sec3, []string{"./sect2"}, ""},
//{"NoPage", sec3, []string{"sect2"}, ""}, // ISSUE: /sect3 page relative query is resolving to /sect2 //{"NoPage", sec3, []string{"sect2"}, ""}, // ISSUE: /sect3 page relative query is resolving to /sect2
{"Abs, ignore context, home", page.KindHome, sec3, []string{"/"}, "home page"}, {"Abs, ignore context, home", kinds.KindHome, sec3, []string{"/"}, "home page"},
{"Abs, ignore context, about", page.KindPage, sec3, []string{"/about.md"}, "about page"}, {"Abs, ignore context, about", kinds.KindPage, sec3, []string{"/about.md"}, "about page"},
{"Abs, ignore context, page in section", page.KindPage, sec3, []string{"/sect4/page2.md"}, "Title4_2"}, {"Abs, ignore context, page in section", kinds.KindPage, sec3, []string{"/sect4/page2.md"}, "Title4_2"},
{"Abs, ignore context, page subsect deep", page.KindPage, sec3, []string{"/sect3/subsect/deep.md"}, "deep page"}, // next test depends on this page existing {"Abs, ignore context, page subsect deep", kinds.KindPage, sec3, []string{"/sect3/subsect/deep.md"}, "deep page"}, // next test depends on this page existing
{"Abs, ignore context, page deep", "NoPage", sec3, []string{"/subsect/deep.md"}, ""}, {"Abs, ignore context, page deep", "NoPage", sec3, []string{"/subsect/deep.md"}, ""},
// Taxonomies // Taxonomies
{"Taxonomy term", page.KindTaxonomy, nil, []string{"categories"}, "Categories"}, {"Taxonomy term", kinds.KindTaxonomy, nil, []string{"categories"}, "Categories"},
{"Taxonomy", page.KindTerm, nil, []string{"categories/hugo", "categories/Hugo"}, "Hugo"}, {"Taxonomy", kinds.KindTerm, nil, []string{"categories/hugo", "categories/Hugo"}, "Hugo"},
// Bundle variants // Bundle variants
{"Bundle regular", page.KindPage, nil, []string{"sect3/b1", "sect3/b1/index.md", "sect3/b1/index.en.md"}, "b1 bundle"}, {"Bundle regular", kinds.KindPage, nil, []string{"sect3/b1", "sect3/b1/index.md", "sect3/b1/index.en.md"}, "b1 bundle"},
{"Bundle index name", page.KindPage, nil, []string{"sect3/index/index.md", "sect3/index"}, "index bundle"}, {"Bundle index name", kinds.KindPage, nil, []string{"sect3/index/index.md", "sect3/index"}, "index bundle"},
// https://github.com/gohugoio/hugo/issues/7301 // https://github.com/gohugoio/hugo/issues/7301
{"Section and bundle overlap", page.KindPage, nil, []string{"section_bundle_overlap_bundle"}, "index overlap bundle"}, {"Section and bundle overlap", kinds.KindPage, nil, []string{"section_bundle_overlap_bundle"}, "index overlap bundle"},
} }
for _, test := range tests { for _, test := range tests {

View file

@ -22,9 +22,9 @@ import (
"testing" "testing"
"github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/parser/pageparser" "github.com/gohugoio/hugo/parser/pageparser"
"github.com/gohugoio/hugo/resources/page"
qt "github.com/frankban/quicktest" qt "github.com/frankban/quicktest"
) )
@ -186,7 +186,7 @@ CSV: {{< myShort >}}
b.Assert(len(h.Sites), qt.Equals, 1) b.Assert(len(h.Sites), qt.Equals, 1)
s := h.Sites[0] s := h.Sites[0]
home := s.getPage(page.KindHome) home := s.getPage(kinds.KindHome)
b.Assert(home, qt.Not(qt.IsNil)) b.Assert(home, qt.Not(qt.IsNil))
b.Assert(len(home.OutputFormats()), qt.Equals, 3) b.Assert(len(home.OutputFormats()), qt.Equals, 3)

View file

@ -52,6 +52,7 @@ import (
"github.com/gohugoio/hugo/langs" "github.com/gohugoio/hugo/langs"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/config"
@ -248,7 +249,7 @@ func (s *Site) initRenderFormats() {
}) })
// Add the per kind configured output formats // Add the per kind configured output formats
for _, kind := range allKindsInPages { for _, kind := range kinds.AllKindsInPages {
if siteFormats, found := s.conf.C.KindOutputFormats[kind]; found { if siteFormats, found := s.conf.C.KindOutputFormats[kind]; found {
for _, f := range siteFormats { for _, f := range siteFormats {
if !formatSet[f.Name] { if !formatSet[f.Name] {
@ -276,9 +277,6 @@ func (s *Site) Languages() langs.Languages {
} }
func (s *Site) isEnabled(kind string) bool { func (s *Site) isEnabled(kind string) bool {
if kind == kindUnknown {
panic("Unknown kind")
}
return s.conf.IsKindEnabled(kind) return s.conf.IsKindEnabled(kind)
} }
@ -1141,19 +1139,19 @@ func (s *Site) publish(statCounter *uint64, path string, r io.Reader, fs afero.F
func (s *Site) kindFromFileInfoOrSections(fi *fileInfo, sections []string) string { func (s *Site) kindFromFileInfoOrSections(fi *fileInfo, sections []string) string {
if fi.TranslationBaseName() == "_index" { if fi.TranslationBaseName() == "_index" {
if fi.Dir() == "" { if fi.Dir() == "" {
return page.KindHome return kinds.KindHome
} }
return s.kindFromSections(sections) return s.kindFromSections(sections)
} }
return page.KindPage return kinds.KindPage
} }
func (s *Site) kindFromSections(sections []string) string { func (s *Site) kindFromSections(sections []string) string {
if len(sections) == 0 { if len(sections) == 0 {
return page.KindHome return kinds.KindHome
} }
return s.kindFromSectionPath(path.Join(sections...)) return s.kindFromSectionPath(path.Join(sections...))
@ -1163,16 +1161,16 @@ func (s *Site) kindFromSectionPath(sectionPath string) string {
var taxonomiesConfig taxonomiesConfig = s.conf.Taxonomies var taxonomiesConfig taxonomiesConfig = s.conf.Taxonomies
for _, plural := range taxonomiesConfig { for _, plural := range taxonomiesConfig {
if plural == sectionPath { if plural == sectionPath {
return page.KindTaxonomy return kinds.KindTaxonomy
} }
if strings.HasPrefix(sectionPath, plural) { if strings.HasPrefix(sectionPath, plural) {
return page.KindTerm return kinds.KindTerm
} }
} }
return page.KindSection return kinds.KindSection
} }
func (s *Site) newPage( func (s *Site) newPage(

View file

@ -40,6 +40,7 @@ import (
"github.com/gohugoio/hugo/navigation" "github.com/gohugoio/hugo/navigation"
"github.com/gohugoio/hugo/output" "github.com/gohugoio/hugo/output"
"github.com/gohugoio/hugo/publisher" "github.com/gohugoio/hugo/publisher"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/resources/page/pagemeta" "github.com/gohugoio/hugo/resources/page/pagemeta"
"github.com/gohugoio/hugo/resources/resource" "github.com/gohugoio/hugo/resources/resource"
@ -185,9 +186,9 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) {
contentMap: newContentMap(contentMapConfig{ contentMap: newContentMap(contentMapConfig{
lang: k, lang: k,
taxonomyConfig: taxonomiesConfig.Values(), taxonomyConfig: taxonomiesConfig.Values(),
taxonomyDisabled: !conf.IsKindEnabled(page.KindTerm), taxonomyDisabled: !conf.IsKindEnabled(kinds.KindTerm),
taxonomyTermDisabled: !conf.IsKindEnabled(page.KindTaxonomy), taxonomyTermDisabled: !conf.IsKindEnabled(kinds.KindTaxonomy),
pageDisabled: !conf.IsKindEnabled(page.KindPage), pageDisabled: !conf.IsKindEnabled(kinds.KindPage),
}), }),
s: s, s: s,
} }

View file

@ -18,7 +18,7 @@ import (
"strings" "strings"
"github.com/gohugoio/hugo/output" "github.com/gohugoio/hugo/output"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/kinds"
"github.com/spf13/cast" "github.com/spf13/cast"
) )
@ -34,20 +34,20 @@ func createDefaultOutputFormats(allFormats output.Formats) map[string]output.For
} }
m := map[string]output.Formats{ m := map[string]output.Formats{
page.KindPage: {htmlOut}, kinds.KindPage: {htmlOut},
page.KindHome: defaultListTypes, kinds.KindHome: defaultListTypes,
page.KindSection: defaultListTypes, kinds.KindSection: defaultListTypes,
page.KindTerm: defaultListTypes, kinds.KindTerm: defaultListTypes,
page.KindTaxonomy: defaultListTypes, kinds.KindTaxonomy: defaultListTypes,
// Below are for consistency. They are currently not used during rendering. // Below are for consistency. They are currently not used during rendering.
kindSitemap: {sitemapOut}, kinds.KindSitemap: {sitemapOut},
kindRobotsTXT: {robotsOut}, kinds.KindRobotsTXT: {robotsOut},
kind404: {htmlOut}, kinds.Kind404: {htmlOut},
} }
// May be disabled // May be disabled
if rssFound { if rssFound {
m[kindRSS] = output.Formats{rssOut} m[kinds.KindRSS] = output.Formats{rssOut}
} }
return m return m
@ -69,7 +69,7 @@ func createSiteOutputFormats(allFormats output.Formats, outputs map[string]any,
seen := make(map[string]bool) seen := make(map[string]bool)
for k, v := range outputs { for k, v := range outputs {
k = getKind(k) k = kinds.GetKindAny(k)
if k == "" { if k == "" {
// Invalid kind // Invalid kind
continue continue

View file

@ -21,7 +21,7 @@ import (
qt "github.com/frankban/quicktest" qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/kinds"
"github.com/spf13/afero" "github.com/spf13/afero"
@ -142,7 +142,7 @@ Len Pages: {{ .Kind }} {{ len .Site.RegularPages }} Page Number: {{ .Paginator.P
s := b.H.Sites[0] s := b.H.Sites[0]
b.Assert(s.language.Lang, qt.Equals, "en") b.Assert(s.language.Lang, qt.Equals, "en")
home := s.getPage(page.KindHome) home := s.getPage(kinds.KindHome)
b.Assert(home, qt.Not(qt.IsNil)) b.Assert(home, qt.Not(qt.IsNil))
@ -314,7 +314,7 @@ baseName = "customdelimbase"
th.assertFileContent("public/nosuffixbase", "no suffix") th.assertFileContent("public/nosuffixbase", "no suffix")
th.assertFileContent("public/customdelimbase_del", "custom delim") th.assertFileContent("public/customdelimbase_del", "custom delim")
home := s.getPage(page.KindHome) home := s.getPage(kinds.KindHome)
c.Assert(home, qt.Not(qt.IsNil)) c.Assert(home, qt.Not(qt.IsNil))
outputs := home.OutputFormats() outputs := home.OutputFormats()
@ -360,8 +360,8 @@ func TestCreateSiteOutputFormats(t *testing.T) {
c := qt.New(t) c := qt.New(t)
outputsConfig := map[string]any{ outputsConfig := map[string]any{
page.KindHome: []string{"HTML", "JSON"}, kinds.KindHome: []string{"HTML", "JSON"},
page.KindSection: []string{"JSON"}, kinds.KindSection: []string{"JSON"},
} }
cfg := config.New() cfg := config.New()
@ -369,21 +369,21 @@ func TestCreateSiteOutputFormats(t *testing.T) {
outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false) outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false)
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
c.Assert(outputs[page.KindSection], deepEqualsOutputFormats, output.Formats{output.JSONFormat}) c.Assert(outputs[kinds.KindSection], deepEqualsOutputFormats, output.Formats{output.JSONFormat})
c.Assert(outputs[page.KindHome], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.JSONFormat}) c.Assert(outputs[kinds.KindHome], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.JSONFormat})
// Defaults // Defaults
c.Assert(outputs[page.KindTerm], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat}) c.Assert(outputs[kinds.KindTerm], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat})
c.Assert(outputs[page.KindTaxonomy], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat}) c.Assert(outputs[kinds.KindTaxonomy], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat})
c.Assert(outputs[page.KindPage], deepEqualsOutputFormats, output.Formats{output.HTMLFormat}) c.Assert(outputs[kinds.KindPage], deepEqualsOutputFormats, output.Formats{output.HTMLFormat})
// These aren't (currently) in use when rendering in Hugo, // These aren't (currently) in use when rendering in Hugo,
// but the pages needs to be assigned an output format, // but the pages needs to be assigned an output format,
// so these should also be correct/sensible. // so these should also be correct/sensible.
c.Assert(outputs[kindRSS], deepEqualsOutputFormats, output.Formats{output.RSSFormat}) c.Assert(outputs[kinds.KindRSS], deepEqualsOutputFormats, output.Formats{output.RSSFormat})
c.Assert(outputs[kindSitemap], deepEqualsOutputFormats, output.Formats{output.SitemapFormat}) c.Assert(outputs[kinds.KindSitemap], deepEqualsOutputFormats, output.Formats{output.SitemapFormat})
c.Assert(outputs[kindRobotsTXT], deepEqualsOutputFormats, output.Formats{output.RobotsTxtFormat}) c.Assert(outputs[kinds.KindRobotsTXT], deepEqualsOutputFormats, output.Formats{output.RobotsTxtFormat})
c.Assert(outputs[kind404], deepEqualsOutputFormats, output.Formats{output.HTMLFormat}) c.Assert(outputs[kinds.Kind404], deepEqualsOutputFormats, output.Formats{output.HTMLFormat})
}) })
// Issue #4528 // Issue #4528
@ -400,7 +400,7 @@ func TestCreateSiteOutputFormats(t *testing.T) {
outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false) outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false)
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
c.Assert(outputs[page.KindTaxonomy], deepEqualsOutputFormats, output.Formats{output.JSONFormat}) c.Assert(outputs[kinds.KindTaxonomy], deepEqualsOutputFormats, output.Formats{output.JSONFormat})
}) })
} }
@ -408,7 +408,7 @@ func TestCreateSiteOutputFormatsInvalidConfig(t *testing.T) {
c := qt.New(t) c := qt.New(t)
outputsConfig := map[string]any{ outputsConfig := map[string]any{
page.KindHome: []string{"FOO", "JSON"}, kinds.KindHome: []string{"FOO", "JSON"},
} }
cfg := config.New() cfg := config.New()
@ -422,7 +422,7 @@ func TestCreateSiteOutputFormatsEmptyConfig(t *testing.T) {
c := qt.New(t) c := qt.New(t)
outputsConfig := map[string]any{ outputsConfig := map[string]any{
page.KindHome: []string{}, kinds.KindHome: []string{},
} }
cfg := config.New() cfg := config.New()
@ -430,14 +430,14 @@ func TestCreateSiteOutputFormatsEmptyConfig(t *testing.T) {
outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false) outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false)
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
c.Assert(outputs[page.KindHome], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat}) c.Assert(outputs[kinds.KindHome], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat})
} }
func TestCreateSiteOutputFormatsCustomFormats(t *testing.T) { func TestCreateSiteOutputFormatsCustomFormats(t *testing.T) {
c := qt.New(t) c := qt.New(t)
outputsConfig := map[string]any{ outputsConfig := map[string]any{
page.KindHome: []string{}, kinds.KindHome: []string{},
} }
cfg := config.New() cfg := config.New()
@ -450,7 +450,7 @@ func TestCreateSiteOutputFormatsCustomFormats(t *testing.T) {
outputs, err := createSiteOutputFormats(output.Formats{customRSS, customHTML}, cfg.GetStringMap("outputs"), false) outputs, err := createSiteOutputFormats(output.Formats{customRSS, customHTML}, cfg.GetStringMap("outputs"), false)
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
c.Assert(outputs[page.KindHome], deepEqualsOutputFormats, output.Formats{customHTML, customRSS}) c.Assert(outputs[kinds.KindHome], deepEqualsOutputFormats, output.Formats{customHTML, customRSS})
} }
// https://github.com/gohugoio/hugo/issues/5849 // https://github.com/gohugoio/hugo/issues/5849

View file

@ -29,6 +29,7 @@ import (
"github.com/gohugoio/hugo/output" "github.com/gohugoio/hugo/output"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/resources/page/pagemeta" "github.com/gohugoio/hugo/resources/page/pagemeta"
) )
@ -228,7 +229,7 @@ func (s *Site) renderPaginator(p *pageState, templ tpl.Template) error {
func (s *Site) render404() error { func (s *Site) render404() error {
p, err := newPageStandalone(&pageMeta{ p, err := newPageStandalone(&pageMeta{
s: s, s: s,
kind: kind404, kind: kinds.Kind404,
urlPaths: pagemeta.URLPath{ urlPaths: pagemeta.URLPath{
URL: "404.html", URL: "404.html",
}, },
@ -244,7 +245,7 @@ func (s *Site) render404() error {
} }
var d layouts.LayoutDescriptor var d layouts.LayoutDescriptor
d.Kind = kind404 d.Kind = kinds.Kind404
templ, found, err := s.Tmpl().LookupLayout(d, output.HTMLFormat) templ, found, err := s.Tmpl().LookupLayout(d, output.HTMLFormat)
if err != nil { if err != nil {
@ -266,7 +267,7 @@ func (s *Site) render404() error {
func (s *Site) renderSitemap() error { func (s *Site) renderSitemap() error {
p, err := newPageStandalone(&pageMeta{ p, err := newPageStandalone(&pageMeta{
s: s, s: s,
kind: kindSitemap, kind: kinds.KindSitemap,
urlPaths: pagemeta.URLPath{ urlPaths: pagemeta.URLPath{
URL: s.conf.Sitemap.Filename, URL: s.conf.Sitemap.Filename,
}, },
@ -294,13 +295,13 @@ func (s *Site) renderSitemap() error {
} }
func (s *Site) renderRobotsTXT() error { func (s *Site) renderRobotsTXT() error {
if !s.conf.EnableRobotsTXT && s.isEnabled(kindRobotsTXT) { if !s.conf.EnableRobotsTXT && s.isEnabled(kinds.KindRobotsTXT) {
return nil return nil
} }
p, err := newPageStandalone(&pageMeta{ p, err := newPageStandalone(&pageMeta{
s: s, s: s,
kind: kindRobotsTXT, kind: kinds.KindRobotsTXT,
urlPaths: pagemeta.URLPath{ urlPaths: pagemeta.URLPath{
URL: "robots.txt", URL: "robots.txt",
}, },

View file

@ -21,6 +21,7 @@ import (
qt "github.com/frankban/quicktest" qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/deps"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
) )
@ -293,7 +294,7 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
}}, }},
} }
home := s.getPage(page.KindHome) home := s.getPage(kinds.KindHome)
for _, test := range tests { for _, test := range tests {
test := test test := test
@ -301,7 +302,7 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
t.Parallel() t.Parallel()
c := qt.New(t) c := qt.New(t)
sections := strings.Split(test.sections, ",") sections := strings.Split(test.sections, ",")
p := s.getPage(page.KindSection, sections...) p := s.getPage(kinds.KindSection, sections...)
c.Assert(p, qt.Not(qt.IsNil), qt.Commentf(fmt.Sprint(sections))) c.Assert(p, qt.Not(qt.IsNil), qt.Commentf(fmt.Sprint(sections)))
if p.Pages() != nil { if p.Pages() != nil {
@ -318,7 +319,7 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
c.Assert(len(home.Sections()), qt.Equals, 9) c.Assert(len(home.Sections()), qt.Equals, 9)
c.Assert(s.Sections(), deepEqualsPages, home.Sections()) c.Assert(s.Sections(), deepEqualsPages, home.Sections())
rootPage := s.getPage(page.KindPage, "mypage.md") rootPage := s.getPage(kinds.KindPage, "mypage.md")
c.Assert(rootPage, qt.Not(qt.IsNil)) c.Assert(rootPage, qt.Not(qt.IsNil))
c.Assert(rootPage.Parent().IsHome(), qt.Equals, true) c.Assert(rootPage.Parent().IsHome(), qt.Equals, true)
// https://github.com/gohugoio/hugo/issues/6365 // https://github.com/gohugoio/hugo/issues/6365
@ -330,7 +331,7 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
// If we later decide to do something about this, we will have to do some normalization in // If we later decide to do something about this, we will have to do some normalization in
// getPage. // getPage.
// TODO(bep) // TODO(bep)
sectionWithSpace := s.getPage(page.KindSection, "Spaces in Section") sectionWithSpace := s.getPage(kinds.KindSection, "Spaces in Section")
c.Assert(sectionWithSpace, qt.Not(qt.IsNil)) c.Assert(sectionWithSpace, qt.Not(qt.IsNil))
c.Assert(sectionWithSpace.RelPermalink(), qt.Equals, "/spaces-in-section/") c.Assert(sectionWithSpace.RelPermalink(), qt.Equals, "/spaces-in-section/")

View file

@ -28,6 +28,7 @@ import (
qt "github.com/frankban/quicktest" qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/deps"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
) )
@ -717,7 +718,7 @@ func TestOrderedPages(t *testing.T) {
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Configs: configs}, BuildCfg{SkipRender: true}) s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Configs: configs}, BuildCfg{SkipRender: true})
if s.getPage(page.KindSection, "sect").Pages()[1].Title() != "Three" || s.getPage(page.KindSection, "sect").Pages()[2].Title() != "Four" { if s.getPage(kinds.KindSection, "sect").Pages()[1].Title() != "Three" || s.getPage(kinds.KindSection, "sect").Pages()[2].Title() != "Four" {
t.Error("Pages in unexpected order.") t.Error("Pages in unexpected order.")
} }
@ -1010,7 +1011,7 @@ func TestRefLinking(t *testing.T) {
t.Parallel() t.Parallel()
site := setupLinkingMockSite(t) site := setupLinkingMockSite(t)
currentPage := site.getPage(page.KindPage, "level2/level3/start.md") currentPage := site.getPage(kinds.KindPage, "level2/level3/start.md")
if currentPage == nil { if currentPage == nil {
t.Fatalf("failed to find current page in site") t.Fatalf("failed to find current page in site")
} }

View file

@ -18,10 +18,9 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/gohugoio/hugo/resources/page"
qt "github.com/frankban/quicktest" qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/deps"
"github.com/gohugoio/hugo/resources/kinds"
) )
const slugDoc1 = "---\ntitle: slug doc 1\nslug: slug-doc-1\naliases:\n - /sd1/foo/\n - /sd2\n - /sd3/\n - /sd4.html\n---\nslug doc 1 content\n" const slugDoc1 = "---\ntitle: slug doc 1\nslug: slug-doc-1\naliases:\n - /sd1/foo/\n - /sd2\n - /sd3/\n - /sd4.html\n---\nslug doc 1 content\n"
@ -68,12 +67,12 @@ Do not go gentle into that good night.
c.Assert(len(s.RegularPages()), qt.Equals, 2) c.Assert(len(s.RegularPages()), qt.Equals, 2)
notUgly := s.getPage(page.KindPage, "sect1/p1.md") notUgly := s.getPage(kinds.KindPage, "sect1/p1.md")
c.Assert(notUgly, qt.Not(qt.IsNil)) c.Assert(notUgly, qt.Not(qt.IsNil))
c.Assert(notUgly.Section(), qt.Equals, "sect1") c.Assert(notUgly.Section(), qt.Equals, "sect1")
c.Assert(notUgly.RelPermalink(), qt.Equals, "/sect1/p1/") c.Assert(notUgly.RelPermalink(), qt.Equals, "/sect1/p1/")
ugly := s.getPage(page.KindPage, "sect2/p2.md") ugly := s.getPage(kinds.KindPage, "sect2/p2.md")
c.Assert(ugly, qt.Not(qt.IsNil)) c.Assert(ugly, qt.Not(qt.IsNil))
c.Assert(ugly.Section(), qt.Equals, "sect2") c.Assert(ugly.Section(), qt.Equals, "sect2")
c.Assert(ugly.RelPermalink(), qt.Equals, "/sect2/p2.html") c.Assert(ugly.RelPermalink(), qt.Equals, "/sect2/p2.html")
@ -125,7 +124,7 @@ Do not go gentle into that good night.
c.Assert(len(s.RegularPages()), qt.Equals, 10) c.Assert(len(s.RegularPages()), qt.Equals, 10)
sect1 := s.getPage(page.KindSection, "sect1") sect1 := s.getPage(kinds.KindSection, "sect1")
c.Assert(sect1, qt.Not(qt.IsNil)) c.Assert(sect1, qt.Not(qt.IsNil))
c.Assert(sect1.RelPermalink(), qt.Equals, "/ss1/") c.Assert(sect1.RelPermalink(), qt.Equals, "/ss1/")
th.assertFileContent(filepath.Join("public", "ss1", "index.html"), "P1|URL: /ss1/|Next: /ss1/page/2/") th.assertFileContent(filepath.Join("public", "ss1", "index.html"), "P1|URL: /ss1/|Next: /ss1/page/2/")

View file

@ -20,6 +20,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
qt "github.com/frankban/quicktest" qt "github.com/frankban/quicktest"
@ -155,8 +156,8 @@ permalinkeds:
s := b.H.Sites[0] s := b.H.Sites[0]
// Make sure that each page.KindTaxonomyTerm page has an appropriate number // Make sure that each kinds.KindTaxonomyTerm page has an appropriate number
// of page.KindTaxonomy pages in its Pages slice. // of kinds.KindTaxonomy pages in its Pages slice.
taxonomyTermPageCounts := map[string]int{ taxonomyTermPageCounts := map[string]int{
"tags": 3, "tags": 3,
"categories": 2, "categories": 2,
@ -167,16 +168,16 @@ permalinkeds:
for taxonomy, count := range taxonomyTermPageCounts { for taxonomy, count := range taxonomyTermPageCounts {
msg := qt.Commentf(taxonomy) msg := qt.Commentf(taxonomy)
term := s.getPage(page.KindTaxonomy, taxonomy) term := s.getPage(kinds.KindTaxonomy, taxonomy)
b.Assert(term, qt.Not(qt.IsNil), msg) b.Assert(term, qt.Not(qt.IsNil), msg)
b.Assert(len(term.Pages()), qt.Equals, count, msg) b.Assert(len(term.Pages()), qt.Equals, count, msg)
for _, p := range term.Pages() { for _, p := range term.Pages() {
b.Assert(p.Kind(), qt.Equals, page.KindTerm) b.Assert(p.Kind(), qt.Equals, kinds.KindTerm)
} }
} }
cat1 := s.getPage(page.KindTerm, "categories", "cat1") cat1 := s.getPage(kinds.KindTerm, "categories", "cat1")
b.Assert(cat1, qt.Not(qt.IsNil)) b.Assert(cat1, qt.Not(qt.IsNil))
if uglyURLs { if uglyURLs {
b.Assert(cat1.RelPermalink(), qt.Equals, "/blog/categories/cat1.html") b.Assert(cat1.RelPermalink(), qt.Equals, "/blog/categories/cat1.html")
@ -184,8 +185,8 @@ permalinkeds:
b.Assert(cat1.RelPermalink(), qt.Equals, "/blog/categories/cat1/") b.Assert(cat1.RelPermalink(), qt.Equals, "/blog/categories/cat1/")
} }
pl1 := s.getPage(page.KindTerm, "permalinkeds", "pl1") pl1 := s.getPage(kinds.KindTerm, "permalinkeds", "pl1")
permalinkeds := s.getPage(page.KindTaxonomy, "permalinkeds") permalinkeds := s.getPage(kinds.KindTaxonomy, "permalinkeds")
b.Assert(pl1, qt.Not(qt.IsNil)) b.Assert(pl1, qt.Not(qt.IsNil))
b.Assert(permalinkeds, qt.Not(qt.IsNil)) b.Assert(permalinkeds, qt.Not(qt.IsNil))
if uglyURLs { if uglyURLs {
@ -196,7 +197,7 @@ permalinkeds:
b.Assert(permalinkeds.RelPermalink(), qt.Equals, "/blog/permalinkeds/") b.Assert(permalinkeds.RelPermalink(), qt.Equals, "/blog/permalinkeds/")
} }
helloWorld := s.getPage(page.KindTerm, "others", "hello-hugo-world") helloWorld := s.getPage(kinds.KindTerm, "others", "hello-hugo-world")
b.Assert(helloWorld, qt.Not(qt.IsNil)) b.Assert(helloWorld, qt.Not(qt.IsNil))
b.Assert(helloWorld.Title(), qt.Equals, "Hello Hugo world") b.Assert(helloWorld.Title(), qt.Equals, "Hello Hugo world")
@ -268,8 +269,8 @@ title: "This is S3s"
return pages return pages
} }
ta := filterbyKind(page.KindTerm) ta := filterbyKind(kinds.KindTerm)
te := filterbyKind(page.KindTaxonomy) te := filterbyKind(kinds.KindTaxonomy)
b.Assert(len(te), qt.Equals, 4) b.Assert(len(te), qt.Equals, 4)
b.Assert(len(ta), qt.Equals, 7) b.Assert(len(ta), qt.Equals, 7)

107
resources/kinds/kinds.go Normal file
View file

@ -0,0 +1,107 @@
// Copyright 2023 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package kinds
import (
"sort"
"strings"
)
const (
KindPage = "page"
// The rest are node types; home page, sections etc.
KindHome = "home"
KindSection = "section"
// Note that before Hugo 0.73 these were confusingly named
// taxonomy (now: term)
// taxonomyTerm (now: taxonomy)
KindTaxonomy = "taxonomy"
KindTerm = "term"
// The following are (currently) temporary nodes,
// i.e. nodes we create just to render in isolation.
KindRSS = "rss"
KindSitemap = "sitemap"
KindRobotsTXT = "robotstxt"
Kind404 = "404"
)
var (
// This is all the kinds we can expect to find in .Site.Pages.
AllKindsInPages []string
// This is all the kinds, including the temporary ones.
AllKinds []string
)
func init() {
for k := range kindMapMain {
AllKindsInPages = append(AllKindsInPages, k)
AllKinds = append(AllKinds, k)
}
for k := range kindMapTemporary {
AllKinds = append(AllKinds, k)
}
// Sort the slices for determinism.
sort.Strings(AllKindsInPages)
sort.Strings(AllKinds)
}
var kindMapMain = map[string]string{
KindPage: KindPage,
KindHome: KindHome,
KindSection: KindSection,
KindTaxonomy: KindTaxonomy,
KindTerm: KindTerm,
// Legacy, pre v0.53.0.
"taxonomyterm": KindTaxonomy,
}
var kindMapTemporary = map[string]string{
KindRSS: KindRSS,
KindSitemap: KindSitemap,
KindRobotsTXT: KindRobotsTXT,
Kind404: Kind404,
}
// GetKindMain gets the page kind given a string, empty if not found.
// Note that this will not return any temporary kinds (e.g. robotstxt).
func GetKindMain(s string) string {
return kindMapMain[strings.ToLower(s)]
}
// GetKindAny gets the page kind given a string, empty if not found.
func GetKindAny(s string) string {
if pkind := GetKindMain(s); pkind != "" {
return pkind
}
return kindMapTemporary[strings.ToLower(s)]
}
// IsDeprecated returns whether the given kind is deprecated.
func IsDeprecated(s string) bool {
s = strings.ToLower(s)
switch s {
case "taxonomyterm":
return true
default:
return false
}
}

View file

@ -1,4 +1,4 @@
// Copyright 2019 The Hugo Authors. All rights reserved. // Copyright 2023 The Hugo Authors. All rights reserved.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package page package kinds
import ( import (
"testing" "testing"
@ -29,9 +29,12 @@ func TestKind(t *testing.T) {
c.Assert(KindTaxonomy, qt.Equals, "taxonomy") c.Assert(KindTaxonomy, qt.Equals, "taxonomy")
c.Assert(KindTerm, qt.Equals, "term") c.Assert(KindTerm, qt.Equals, "term")
c.Assert(GetKind("TAXONOMYTERM"), qt.Equals, KindTaxonomy) c.Assert(GetKindMain("TAXONOMYTERM"), qt.Equals, KindTaxonomy)
c.Assert(GetKind("Taxonomy"), qt.Equals, KindTaxonomy) c.Assert(GetKindMain("Taxonomy"), qt.Equals, KindTaxonomy)
c.Assert(GetKind("Page"), qt.Equals, KindPage) c.Assert(GetKindMain("Page"), qt.Equals, KindPage)
c.Assert(GetKind("Home"), qt.Equals, KindHome) c.Assert(GetKindMain("Home"), qt.Equals, KindHome)
c.Assert(GetKind("SEction"), qt.Equals, KindSection) c.Assert(GetKindMain("SEction"), qt.Equals, KindSection)
c.Assert(GetKindAny("Page"), qt.Equals, KindPage)
c.Assert(GetKindAny("Robotstxt"), qt.Equals, KindRobotsTXT)
} }

View file

@ -12,36 +12,3 @@
// limitations under the License. // limitations under the License.
package page package page
import "strings"
const (
KindPage = "page"
// The rest are node types; home page, sections etc.
KindHome = "home"
KindSection = "section"
// Note that before Hugo 0.73 these were confusingly named
// taxonomy (now: term)
// taxonomyTerm (now: taxonomy)
KindTaxonomy = "taxonomy"
KindTerm = "term"
)
var kindMap = map[string]string{
strings.ToLower(KindPage): KindPage,
strings.ToLower(KindHome): KindHome,
strings.ToLower(KindSection): KindSection,
strings.ToLower(KindTaxonomy): KindTaxonomy,
strings.ToLower(KindTerm): KindTerm,
// Legacy, pre v0.53.0.
"taxonomyterm": KindTaxonomy,
}
// GetKind gets the page kind given a string, empty if not found.
func GetKind(s string) string {
return kindMap[strings.ToLower(s)]
}

View file

@ -21,6 +21,7 @@ import (
"github.com/gohugoio/hugo/common/maps" "github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/hugofs/glob" "github.com/gohugoio/hugo/hugofs/glob"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
) )
@ -173,7 +174,7 @@ func decodePageMatcher(m any, v *PageMatcher) error {
if v.Kind != "" { if v.Kind != "" {
g, _ := glob.GetGlob(v.Kind) g, _ := glob.GetGlob(v.Kind)
found := false found := false
for _, k := range kindMap { for _, k := range kinds.AllKindsInPages {
if g.Match(k) { if g.Match(k) {
found = true found = true
break break

View file

@ -21,6 +21,7 @@ import (
"github.com/gohugoio/hugo/common/urls" "github.com/gohugoio/hugo/common/urls"
"github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/output" "github.com/gohugoio/hugo/output"
"github.com/gohugoio/hugo/resources/kinds"
) )
const slash = "/" const slash = "/"
@ -147,7 +148,7 @@ func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths) {
isUgly = true isUgly = true
} }
if d.Kind != KindPage && d.URL == "" && len(d.Sections) > 0 { if d.Kind != kinds.KindPage && d.URL == "" && len(d.Sections) > 0 {
if d.ExpandedPermalink != "" { if d.ExpandedPermalink != "" {
pagePath = pjoin(pagePath, d.ExpandedPermalink) pagePath = pjoin(pagePath, d.ExpandedPermalink)
} else { } else {
@ -160,7 +161,7 @@ func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths) {
pagePath = pjoin(pagePath, d.Type.Path) pagePath = pjoin(pagePath, d.Type.Path)
} }
if d.Kind != KindHome && d.URL != "" { if d.Kind != kinds.KindHome && d.URL != "" {
pagePath = pjoin(pagePath, d.URL) pagePath = pjoin(pagePath, d.URL)
if d.Addends != "" { if d.Addends != "" {
@ -200,7 +201,7 @@ func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths) {
} }
} }
} else if d.Kind == KindPage { } else if d.Kind == kinds.KindPage {
if d.ExpandedPermalink != "" { if d.ExpandedPermalink != "" {
pagePath = pjoin(pagePath, d.ExpandedPermalink) pagePath = pjoin(pagePath, d.ExpandedPermalink)
@ -307,7 +308,7 @@ func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths) {
// if page URL is explicitly set in frontmatter, // if page URL is explicitly set in frontmatter,
// preserve its value without sanitization // preserve its value without sanitization
if d.Kind != KindPage || d.URL == "" { if d.Kind != kinds.KindPage || d.URL == "" {
// Note: MakePathSanitized will lower case the path if // Note: MakePathSanitized will lower case the path if
// disablePathToLower isn't set. // disablePathToLower isn't set.
pagePath = d.PathSpec.MakePathSanitized(pagePath) pagePath = d.PathSpec.MakePathSanitized(pagePath)

View file

@ -20,6 +20,7 @@ import (
"testing" "testing"
"github.com/gohugoio/hugo/media" "github.com/gohugoio/hugo/media"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/output" "github.com/gohugoio/hugo/output"
@ -47,31 +48,31 @@ func TestPageTargetPath(t *testing.T) {
d page.TargetPathDescriptor d page.TargetPathDescriptor
expected page.TargetPaths expected page.TargetPaths
}{ }{
{"JSON home", page.TargetPathDescriptor{Kind: page.KindHome, Type: output.JSONFormat}, page.TargetPaths{TargetFilename: "/index.json", SubResourceBaseTarget: "", Link: "/index.json"}}, {"JSON home", page.TargetPathDescriptor{Kind: kinds.KindHome, Type: output.JSONFormat}, page.TargetPaths{TargetFilename: "/index.json", SubResourceBaseTarget: "", Link: "/index.json"}},
{"AMP home", page.TargetPathDescriptor{Kind: page.KindHome, Type: output.AMPFormat}, page.TargetPaths{TargetFilename: "/amp/index.html", SubResourceBaseTarget: "/amp", Link: "/amp/"}}, {"AMP home", page.TargetPathDescriptor{Kind: kinds.KindHome, Type: output.AMPFormat}, page.TargetPaths{TargetFilename: "/amp/index.html", SubResourceBaseTarget: "/amp", Link: "/amp/"}},
{"HTML home", page.TargetPathDescriptor{Kind: page.KindHome, BaseName: "_index", Type: output.HTMLFormat}, page.TargetPaths{TargetFilename: "/index.html", SubResourceBaseTarget: "", Link: "/"}}, {"HTML home", page.TargetPathDescriptor{Kind: kinds.KindHome, BaseName: "_index", Type: output.HTMLFormat}, page.TargetPaths{TargetFilename: "/index.html", SubResourceBaseTarget: "", Link: "/"}},
{"Netlify redirects", page.TargetPathDescriptor{Kind: page.KindHome, BaseName: "_index", Type: noExtDelimFormat}, page.TargetPaths{TargetFilename: "/_redirects", SubResourceBaseTarget: "", Link: "/_redirects"}}, {"Netlify redirects", page.TargetPathDescriptor{Kind: kinds.KindHome, BaseName: "_index", Type: noExtDelimFormat}, page.TargetPaths{TargetFilename: "/_redirects", SubResourceBaseTarget: "", Link: "/_redirects"}},
{"HTML section list", page.TargetPathDescriptor{ {"HTML section list", page.TargetPathDescriptor{
Kind: page.KindSection, Kind: kinds.KindSection,
Sections: []string{"sect1"}, Sections: []string{"sect1"},
BaseName: "_index", BaseName: "_index",
Type: output.HTMLFormat, Type: output.HTMLFormat,
}, page.TargetPaths{TargetFilename: "/sect1/index.html", SubResourceBaseTarget: "/sect1", Link: "/sect1/"}}, }, page.TargetPaths{TargetFilename: "/sect1/index.html", SubResourceBaseTarget: "/sect1", Link: "/sect1/"}},
{"HTML taxonomy term", page.TargetPathDescriptor{ {"HTML taxonomy term", page.TargetPathDescriptor{
Kind: page.KindTerm, Kind: kinds.KindTerm,
Sections: []string{"tags", "hugo"}, Sections: []string{"tags", "hugo"},
BaseName: "_index", BaseName: "_index",
Type: output.HTMLFormat, Type: output.HTMLFormat,
}, page.TargetPaths{TargetFilename: "/tags/hugo/index.html", SubResourceBaseTarget: "/tags/hugo", Link: "/tags/hugo/"}}, }, page.TargetPaths{TargetFilename: "/tags/hugo/index.html", SubResourceBaseTarget: "/tags/hugo", Link: "/tags/hugo/"}},
{"HTML taxonomy", page.TargetPathDescriptor{ {"HTML taxonomy", page.TargetPathDescriptor{
Kind: page.KindTaxonomy, Kind: kinds.KindTaxonomy,
Sections: []string{"tags"}, Sections: []string{"tags"},
BaseName: "_index", BaseName: "_index",
Type: output.HTMLFormat, Type: output.HTMLFormat,
}, page.TargetPaths{TargetFilename: "/tags/index.html", SubResourceBaseTarget: "/tags", Link: "/tags/"}}, }, page.TargetPaths{TargetFilename: "/tags/index.html", SubResourceBaseTarget: "/tags", Link: "/tags/"}},
{ {
"HTML page", page.TargetPathDescriptor{ "HTML page", page.TargetPathDescriptor{
Kind: page.KindPage, Kind: kinds.KindPage,
Dir: "/a/b", Dir: "/a/b",
BaseName: "mypage", BaseName: "mypage",
Sections: []string{"a"}, Sections: []string{"a"},
@ -81,7 +82,7 @@ func TestPageTargetPath(t *testing.T) {
{ {
"HTML page with index as base", page.TargetPathDescriptor{ "HTML page with index as base", page.TargetPathDescriptor{
Kind: page.KindPage, Kind: kinds.KindPage,
Dir: "/a/b", Dir: "/a/b",
BaseName: "index", BaseName: "index",
Sections: []string{"a"}, Sections: []string{"a"},
@ -91,7 +92,7 @@ func TestPageTargetPath(t *testing.T) {
{ {
"HTML page with special chars", page.TargetPathDescriptor{ "HTML page with special chars", page.TargetPathDescriptor{
Kind: page.KindPage, Kind: kinds.KindPage,
Dir: "/a/b", Dir: "/a/b",
BaseName: "My Page!", BaseName: "My Page!",
Type: output.HTMLFormat, Type: output.HTMLFormat,
@ -105,7 +106,7 @@ func TestPageTargetPath(t *testing.T) {
}, page.TargetPaths{TargetFilename: "/sect1/index.xml", SubResourceBaseTarget: "/sect1", Link: "/sect1/index.xml"}}, }, page.TargetPaths{TargetFilename: "/sect1/index.xml", SubResourceBaseTarget: "/sect1", Link: "/sect1/index.xml"}},
{ {
"AMP page", page.TargetPathDescriptor{ "AMP page", page.TargetPathDescriptor{
Kind: page.KindPage, Kind: kinds.KindPage,
Dir: "/a/b/c", Dir: "/a/b/c",
BaseName: "myamp", BaseName: "myamp",
Type: output.AMPFormat, Type: output.AMPFormat,
@ -113,7 +114,7 @@ func TestPageTargetPath(t *testing.T) {
}, },
{ {
"AMP page with URL with suffix", page.TargetPathDescriptor{ "AMP page with URL with suffix", page.TargetPathDescriptor{
Kind: page.KindPage, Kind: kinds.KindPage,
Dir: "/sect/", Dir: "/sect/",
BaseName: "mypage", BaseName: "mypage",
URL: "/some/other/url.xhtml", URL: "/some/other/url.xhtml",
@ -122,7 +123,7 @@ func TestPageTargetPath(t *testing.T) {
}, },
{ {
"JSON page with URL without suffix", page.TargetPathDescriptor{ "JSON page with URL without suffix", page.TargetPathDescriptor{
Kind: page.KindPage, Kind: kinds.KindPage,
Dir: "/sect/", Dir: "/sect/",
BaseName: "mypage", BaseName: "mypage",
URL: "/some/other/path/", URL: "/some/other/path/",
@ -131,7 +132,7 @@ func TestPageTargetPath(t *testing.T) {
}, },
{ {
"JSON page with URL without suffix and no trailing slash", page.TargetPathDescriptor{ "JSON page with URL without suffix and no trailing slash", page.TargetPathDescriptor{
Kind: page.KindPage, Kind: kinds.KindPage,
Dir: "/sect/", Dir: "/sect/",
BaseName: "mypage", BaseName: "mypage",
URL: "/some/other/path", URL: "/some/other/path",
@ -140,7 +141,7 @@ func TestPageTargetPath(t *testing.T) {
}, },
{ {
"HTML page with URL without suffix and no trailing slash", page.TargetPathDescriptor{ "HTML page with URL without suffix and no trailing slash", page.TargetPathDescriptor{
Kind: page.KindPage, Kind: kinds.KindPage,
Dir: "/sect/", Dir: "/sect/",
BaseName: "mypage", BaseName: "mypage",
URL: "/some/other/path", URL: "/some/other/path",
@ -149,7 +150,7 @@ func TestPageTargetPath(t *testing.T) {
}, },
{ {
"HTML page with URL containing double hyphen", page.TargetPathDescriptor{ "HTML page with URL containing double hyphen", page.TargetPathDescriptor{
Kind: page.KindPage, Kind: kinds.KindPage,
Dir: "/sect/", Dir: "/sect/",
BaseName: "mypage", BaseName: "mypage",
URL: "/some/other--url/", URL: "/some/other--url/",
@ -158,7 +159,7 @@ func TestPageTargetPath(t *testing.T) {
}, },
{ {
"HTML page with expanded permalink", page.TargetPathDescriptor{ "HTML page with expanded permalink", page.TargetPathDescriptor{
Kind: page.KindPage, Kind: kinds.KindPage,
Dir: "/a/b", Dir: "/a/b",
BaseName: "mypage", BaseName: "mypage",
ExpandedPermalink: "/2017/10/my-title/", ExpandedPermalink: "/2017/10/my-title/",
@ -167,7 +168,7 @@ func TestPageTargetPath(t *testing.T) {
}, },
{ {
"Paginated HTML home", page.TargetPathDescriptor{ "Paginated HTML home", page.TargetPathDescriptor{
Kind: page.KindHome, Kind: kinds.KindHome,
BaseName: "_index", BaseName: "_index",
Type: output.HTMLFormat, Type: output.HTMLFormat,
Addends: "page/3", Addends: "page/3",
@ -175,7 +176,7 @@ func TestPageTargetPath(t *testing.T) {
}, },
{ {
"Paginated Taxonomy terms list", page.TargetPathDescriptor{ "Paginated Taxonomy terms list", page.TargetPathDescriptor{
Kind: page.KindTerm, Kind: kinds.KindTerm,
BaseName: "_index", BaseName: "_index",
Sections: []string{"tags", "hugo"}, Sections: []string{"tags", "hugo"},
Type: output.HTMLFormat, Type: output.HTMLFormat,
@ -184,7 +185,7 @@ func TestPageTargetPath(t *testing.T) {
}, },
{ {
"Regular page with addend", page.TargetPathDescriptor{ "Regular page with addend", page.TargetPathDescriptor{
Kind: page.KindPage, Kind: kinds.KindPage,
Dir: "/a/b", Dir: "/a/b",
BaseName: "mypage", BaseName: "mypage",
Addends: "c/d/e", Addends: "c/d/e",
@ -207,8 +208,8 @@ func TestPageTargetPath(t *testing.T) {
expected := test.expected expected := test.expected
// TODO(bep) simplify // TODO(bep) simplify
if test.d.Kind == page.KindPage && test.d.BaseName == test.d.Type.BaseName { if test.d.Kind == kinds.KindPage && test.d.BaseName == test.d.Type.BaseName {
} else if test.d.Kind == page.KindHome && test.d.Type.Path != "" { } else if test.d.Kind == kinds.KindHome && test.d.Type.Path != "" {
} else if test.d.Type.MediaType.FirstSuffix.Suffix != "" && (!strings.HasPrefix(expected.TargetFilename, "/index") || test.d.Addends != "") && test.d.URL == "" && isUgly { } else if test.d.Type.MediaType.FirstSuffix.Suffix != "" && (!strings.HasPrefix(expected.TargetFilename, "/index") || test.d.Addends != "") && test.d.URL == "" && isUgly {
expected.TargetFilename = strings.Replace(expected.TargetFilename, expected.TargetFilename = strings.Replace(expected.TargetFilename,
"/"+test.d.Type.BaseName+"."+test.d.Type.MediaType.FirstSuffix.Suffix, "/"+test.d.Type.BaseName+"."+test.d.Type.MediaType.FirstSuffix.Suffix,
@ -250,12 +251,12 @@ func TestPageTargetPathPrefix(t *testing.T) {
}{ }{
{ {
"URL set, prefix both, no force", "URL set, prefix both, no force",
page.TargetPathDescriptor{Kind: page.KindPage, Type: output.JSONFormat, URL: "/mydir/my.json", ForcePrefix: false, PrefixFilePath: "pf", PrefixLink: "pl"}, page.TargetPathDescriptor{Kind: kinds.KindPage, Type: output.JSONFormat, URL: "/mydir/my.json", ForcePrefix: false, PrefixFilePath: "pf", PrefixLink: "pl"},
page.TargetPaths{TargetFilename: "/mydir/my.json", SubResourceBaseTarget: "/mydir", SubResourceBaseLink: "/mydir", Link: "/mydir/my.json"}, page.TargetPaths{TargetFilename: "/mydir/my.json", SubResourceBaseTarget: "/mydir", SubResourceBaseLink: "/mydir", Link: "/mydir/my.json"},
}, },
{ {
"URL set, prefix both, force", "URL set, prefix both, force",
page.TargetPathDescriptor{Kind: page.KindPage, Type: output.JSONFormat, URL: "/mydir/my.json", ForcePrefix: true, PrefixFilePath: "pf", PrefixLink: "pl"}, page.TargetPathDescriptor{Kind: kinds.KindPage, Type: output.JSONFormat, URL: "/mydir/my.json", ForcePrefix: true, PrefixFilePath: "pf", PrefixLink: "pl"},
page.TargetPaths{TargetFilename: "/pf/mydir/my.json", SubResourceBaseTarget: "/pf/mydir", SubResourceBaseLink: "/pl/mydir", Link: "/pl/mydir/my.json"}, page.TargetPaths{TargetFilename: "/pf/mydir/my.json", SubResourceBaseTarget: "/pf/mydir", SubResourceBaseLink: "/pl/mydir", Link: "/pl/mydir/my.json"},
}, },
} }

View file

@ -27,6 +27,7 @@ import (
"github.com/gohugoio/hugo/common/maps" "github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/resources/kinds"
) )
// PermalinkExpander holds permalin mappings per section. // PermalinkExpander holds permalin mappings per section.
@ -398,16 +399,16 @@ func (l PermalinkExpander) toSliceFunc(cut string) func(s []string) []string {
} }
var permalinksKindsSuppurt = []string{KindPage, KindSection, KindTaxonomy, KindTerm} var permalinksKindsSuppurt = []string{kinds.KindPage, kinds.KindSection, kinds.KindTaxonomy, kinds.KindTerm}
// DecodePermalinksConfig decodes the permalinks configuration in the given map // DecodePermalinksConfig decodes the permalinks configuration in the given map
func DecodePermalinksConfig(m map[string]any) (map[string]map[string]string, error) { func DecodePermalinksConfig(m map[string]any) (map[string]map[string]string, error) {
permalinksConfig := make(map[string]map[string]string) permalinksConfig := make(map[string]map[string]string)
permalinksConfig[KindPage] = make(map[string]string) permalinksConfig[kinds.KindPage] = make(map[string]string)
permalinksConfig[KindSection] = make(map[string]string) permalinksConfig[kinds.KindSection] = make(map[string]string)
permalinksConfig[KindTaxonomy] = make(map[string]string) permalinksConfig[kinds.KindTaxonomy] = make(map[string]string)
permalinksConfig[KindTerm] = make(map[string]string) permalinksConfig[kinds.KindTerm] = make(map[string]string)
config := maps.CleanConfigStringMap(m) config := maps.CleanConfigStringMap(m)
for k, v := range config { for k, v := range config {
@ -417,8 +418,8 @@ func DecodePermalinksConfig(m map[string]any) (map[string]map[string]string, err
// key = '...' // key = '...'
// To sucessfully be backward compatible, "default" patterns need to be set for both page and term // To sucessfully be backward compatible, "default" patterns need to be set for both page and term
permalinksConfig[KindPage][k] = v permalinksConfig[kinds.KindPage][k] = v
permalinksConfig[KindTerm][k] = v permalinksConfig[kinds.KindTerm][k] = v
case maps.Params: case maps.Params:
// [permalinks.key] // [permalinks.key]