]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Move all Kind constants to its own package
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 28 Jul 2023 08:53:47 +0000 (10:53 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 28 Jul 2023 13:14:23 +0000 (15:14 +0200)
See #11256

36 files changed:
config/allconfig/allconfig.go
hugolib/content_map.go
hugolib/content_map_page.go
hugolib/disableKinds_test.go
hugolib/hugo_sites.go
hugolib/hugo_sites_build_test.go
hugolib/hugo_sites_multihost_test.go
hugolib/language_content_dir_test.go
hugolib/page.go
hugolib/page__data.go
hugolib/page__meta.go
hugolib/page__paginator.go
hugolib/page__paths.go
hugolib/page__tree.go
hugolib/page_kinds.go
hugolib/pagebundler_test.go
hugolib/pagecollections.go
hugolib/pagecollections_test.go
hugolib/shortcode_test.go
hugolib/site.go
hugolib/site_new.go
hugolib/site_output.go
hugolib/site_output_test.go
hugolib/site_render.go
hugolib/site_sections_test.go
hugolib/site_test.go
hugolib/site_url_test.go
hugolib/taxonomy_test.go
resources/kinds/kinds.go [new file with mode: 0644]
resources/kinds/kinds_test.go [new file with mode: 0644]
resources/page/page_kinds.go
resources/page/page_kinds_test.go [deleted file]
resources/page/page_matcher.go
resources/page/page_paths.go
resources/page/page_paths_test.go
resources/page/permalinks.go

index ec95f5eba885c0d23ff3dfbf024692389376f5a7..6d206d7a40d41f2edef3ab9d5c857ec30ac72b9c 100644 (file)
@@ -45,6 +45,7 @@ import (
        "github.com/gohugoio/hugo/output"
        "github.com/gohugoio/hugo/related"
        "github.com/gohugoio/hugo/resources/images"
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/gohugoio/hugo/resources/page"
        "github.com/gohugoio/hugo/resources/page/pagemeta"
        "github.com/spf13/afero"
@@ -940,11 +941,11 @@ func createDefaultOutputFormats(allFormats output.Formats) map[string][]string {
        }
 
        m := map[string][]string{
-               page.KindPage:     {htmlOut.Name},
-               page.KindHome:     defaultListTypes,
-               page.KindSection:  defaultListTypes,
-               page.KindTerm:     defaultListTypes,
-               page.KindTaxonomy: defaultListTypes,
+               kinds.KindPage:     {htmlOut.Name},
+               kinds.KindHome:     defaultListTypes,
+               kinds.KindSection:  defaultListTypes,
+               kinds.KindTerm:     defaultListTypes,
+               kinds.KindTaxonomy: defaultListTypes,
        }
 
        // May be disabled
index 9abf0d5b0678131f07760b35e54567e621a77193..8cb3076912e774b5ffd8d7ca9a1b18696c009abf 100644 (file)
@@ -22,6 +22,7 @@ import (
 
        "github.com/gohugoio/hugo/helpers"
 
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/gohugoio/hugo/resources/page"
 
        "github.com/gohugoio/hugo/hugofs/files"
@@ -275,13 +276,13 @@ type contentBundleViewInfo struct {
 
 func (c *contentBundleViewInfo) kind() string {
        if c.termKey != "" {
-               return page.KindTerm
+               return kinds.KindTerm
        }
-       return page.KindTaxonomy
+       return kinds.KindTaxonomy
 }
 
 func (c *contentBundleViewInfo) sections() []string {
-       if c.kind() == page.KindTaxonomy {
+       if c.kind() == kinds.KindTaxonomy {
                return []string{c.name.plural}
        }
 
index 6f02e2e2956d9a0d07fb4aceb60ee50dd4385747..e7f6c5aed55e7cf6f764f0d176f3952f54495523 100644 (file)
@@ -19,6 +19,7 @@ import (
        "path"
        "path/filepath"
        "strings"
+
        "sync"
 
        "github.com/gohugoio/hugo/common/maps"
@@ -30,6 +31,7 @@ import (
        "github.com/gohugoio/hugo/hugofs"
        "github.com/gohugoio/hugo/hugofs/files"
        "github.com/gohugoio/hugo/parser/pageparser"
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/gohugoio/hugo/resources/page"
        "github.com/gohugoio/hugo/resources/resource"
        "github.com/spf13/cast"
@@ -105,7 +107,7 @@ func (m *pageMap) newPageFromContentNode(n *contentNode, parentBucket *pagesMapB
        sections := s.sectionsFromFile(f)
 
        kind := s.kindFromFileInfoOrSections(f, sections)
-       if kind == page.KindTerm {
+       if kind == kinds.KindTerm {
                s.PathSpec.MakePathsSanitized(sections)
        }
 
@@ -366,7 +368,7 @@ func (m *pageMap) assemblePages() error {
                        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 {
                        m.deletePage(s)
                        return false
@@ -469,9 +471,9 @@ func (m *pageMap) assembleSections() error {
                        parentBucket = m.s.siteBucket
                }
 
-               kind := page.KindSection
+               kind := kinds.KindSection
                if s == "/" {
-                       kind = page.KindHome
+                       kind = kinds.KindHome
                }
 
                if n.fi != nil {
@@ -537,7 +539,7 @@ func (m *pageMap) assembleTaxonomies() error {
                        }
                } else {
                        title := ""
-                       if kind == page.KindTerm {
+                       if kind == kinds.KindTerm {
                                title = n.viewInfo.term()
                        }
                        n.p = m.s.newPage(n, parent.p.bucket, kind, title, sections...)
index 87a60d636ecd73cca72d686372a2183b30e5ef57..c24f6b10e6222db7236cec8fcc7f8be9bc95a0c4 100644 (file)
@@ -17,6 +17,7 @@ import (
        "testing"
 
        qt "github.com/frankban/quicktest"
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/gohugoio/hugo/resources/page"
 )
 
@@ -134,7 +135,7 @@ title: Headless Local Lists Sub
                return nil
        }
 
-       disableKind := page.KindPage
+       disableKind := kinds.KindPage
        c.Run("Disable "+disableKind, func(c *qt.C) {
                b := newSitesBuilder(c, disableKind)
                b.Build(BuildCfg{})
@@ -149,7 +150,7 @@ title: Headless Local Lists Sub
                b.Assert(len(s.Taxonomies()["categories"]), qt.Equals, 0)
        })
 
-       disableKind = page.KindTerm
+       disableKind = kinds.KindTerm
        c.Run("Disable "+disableKind, func(c *qt.C) {
                b := newSitesBuilder(c, disableKind)
                b.Build(BuildCfg{})
@@ -161,7 +162,7 @@ title: Headless Local Lists Sub
                b.Assert(getPage(b, "/categories/mycat"), qt.IsNil)
        })
 
-       disableKind = page.KindTaxonomy
+       disableKind = kinds.KindTaxonomy
        c.Run("Disable "+disableKind, func(c *qt.C) {
                b := newSitesBuilder(c, disableKind)
                b.Build(BuildCfg{})
@@ -177,7 +178,7 @@ title: Headless Local Lists Sub
                b.Assert(getPageInPagePages(getPage(b, "/"), "/categories"), qt.IsNil)
        })
 
-       disableKind = page.KindHome
+       disableKind = kinds.KindHome
        c.Run("Disable "+disableKind, func(c *qt.C) {
                b := newSitesBuilder(c, disableKind)
                b.Build(BuildCfg{})
@@ -190,7 +191,7 @@ title: Headless Local Lists Sub
                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) {
                b := newSitesBuilder(c, disableKind)
                b.Build(BuildCfg{})
@@ -210,7 +211,7 @@ title: Headless Local Lists Sub
                b.AssertFileContent("public/index.xml", "rss")
        })
 
-       disableKind = kindRSS
+       disableKind = kinds.KindRSS
        c.Run("Disable "+disableKind, func(c *qt.C) {
                b := newSitesBuilder(c, disableKind)
                b.Build(BuildCfg{})
@@ -219,21 +220,21 @@ title: Headless Local Lists Sub
                b.Assert(home.OutputFormats(), qt.HasLen, 1)
        })
 
-       disableKind = kindSitemap
+       disableKind = kinds.KindSitemap
        c.Run("Disable "+disableKind, func(c *qt.C) {
                b := newSitesBuilder(c, disableKind)
                b.Build(BuildCfg{})
                b.Assert(b.CheckExists("public/sitemap.xml"), qt.Equals, false)
        })
 
-       disableKind = kind404
+       disableKind = kinds.Kind404
        c.Run("Disable "+disableKind, func(c *qt.C) {
                b := newSitesBuilder(c, disableKind)
                b.Build(BuildCfg{})
                b.Assert(b.CheckExists("public/404.html"), qt.Equals, false)
        })
 
-       disableKind = kindRobotsTXT
+       disableKind = kinds.KindRobotsTXT
        c.Run("Disable "+disableKind, func(c *qt.C) {
                b := newSitesBuilder(c, disableKind)
                b.WithTemplatesAdded("robots.txt", "myrobots")
index 3b5efa2e559ac5c66e3acfce100e1335206f180a..eb0385cda469d84633e279534ee29b9a9fbe947e 100644 (file)
@@ -47,6 +47,7 @@ import (
        "github.com/gohugoio/hugo/helpers"
        "github.com/gohugoio/hugo/lazy"
 
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/gohugoio/hugo/resources/page"
        "github.com/gohugoio/hugo/resources/page/pagemeta"
        "github.com/gohugoio/hugo/tpl"
@@ -443,7 +444,7 @@ func (h *HugoSites) renderCrossSitesSitemap() error {
 
        sitemapEnabled := false
        for _, s := range h.Sites {
-               if s.conf.IsKindEnabled(kindSitemap) {
+               if s.conf.IsKindEnabled(kinds.KindSitemap) {
                        sitemapEnabled = true
                        break
                }
@@ -474,7 +475,7 @@ func (h *HugoSites) renderCrossSitesRobotsTXT() error {
 
        p, err := newPageStandalone(&pageMeta{
                s:    s,
-               kind: kindRobotsTXT,
+               kind: kinds.KindRobotsTXT,
                urlPaths: pagemeta.URLPath{
                        URL: "robots.txt",
                },
@@ -523,7 +524,7 @@ func (h *HugoSites) createPageCollections() error {
        })
 
        allRegularPages := newLazyPagesFactory(func() page.Pages {
-               return h.findPagesByKindIn(page.KindPage, allPages.get())
+               return h.findPagesByKindIn(kinds.KindPage, allPages.get())
        })
 
        for _, s := range h.Sites {
index 3c82a60b68b56ae4b63f9ea6d5ff301fe04f03d6..bdbf4270eb9e1cc01a19c5ded74e0510f8e8a687 100644 (file)
@@ -10,7 +10,7 @@ import (
        qt "github.com/frankban/quicktest"
        "github.com/gohugoio/hugo/common/loggers"
        "github.com/gohugoio/hugo/htesting"
-       "github.com/gohugoio/hugo/resources/page"
+       "github.com/gohugoio/hugo/resources/kinds"
 
        "github.com/fortytw2/leaktest"
        "github.com/fsnotify/fsnotify"
@@ -182,12 +182,12 @@ p1 = "p1en"
        c.Assert(len(sites), qt.Equals, 2)
 
        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.Translations()), qt.Equals, 1)
        c.Assert(nnHome.IsTranslated(), qt.Equals, true)
 
-       enHome := sites[1].getPage(page.KindHome)
+       enHome := sites[1].getPage(kinds.KindHome)
 
        p1, err := enHome.Param("p1")
        c.Assert(err, qt.IsNil)
@@ -239,7 +239,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
        c.Assert(gp2, qt.IsNil)
 
        enSite := sites[0]
-       enSiteHome := enSite.getPage(page.KindHome)
+       enSiteHome := enSite.getPage(kinds.KindHome)
        c.Assert(enSiteHome.IsTranslated(), qt.Equals, true)
 
        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.
        // Now you can do lookups with translation base name to get that behaviour.
        // Let us test all the regular page variants:
-       getPageDoc1En := enSite.getPage(page.KindPage, filepath.ToSlash(doc1en.File().Path()))
-       getPageDoc1EnBase := enSite.getPage(page.KindPage, "sect/doc1")
-       getPageDoc1Fr := frSite.getPage(page.KindPage, filepath.ToSlash(doc1fr.File().Path()))
-       getPageDoc1FrBase := frSite.getPage(page.KindPage, "sect/doc1")
+       getPageDoc1En := enSite.getPage(kinds.KindPage, filepath.ToSlash(doc1en.File().Path()))
+       getPageDoc1EnBase := enSite.getPage(kinds.KindPage, "sect/doc1")
+       getPageDoc1Fr := frSite.getPage(kinds.KindPage, filepath.ToSlash(doc1fr.File().Path()))
+       getPageDoc1FrBase := frSite.getPage(kinds.KindPage, "sect/doc1")
        c.Assert(getPageDoc1En, qt.Equals, doc1en)
        c.Assert(getPageDoc1Fr, qt.Equals, doc1fr)
        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")
 
        // Check node translations
-       homeEn := enSite.getPage(page.KindHome)
+       homeEn := enSite.getPage(kinds.KindHome)
        c.Assert(homeEn, qt.Not(qt.IsNil))
        c.Assert(len(homeEn.Translations()), qt.Equals, 3)
        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].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.Language().Lang, qt.Equals, "fr")
@@ -341,14 +341,14 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
 
        nnSite := sites[2]
        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(len(taxNn.Translations()), qt.Equals, 1)
        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(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(taxTermNn.Translations()[0].Language().Lang, qt.Equals, "nb")
 
@@ -379,19 +379,19 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
        // Issue #3108
        prevPage := enSite.RegularPages()[0].Prev()
        c.Assert(prevPage, qt.Not(qt.IsNil))
-       c.Assert(prevPage.Kind(), qt.Equals, page.KindPage)
+       c.Assert(prevPage.Kind(), qt.Equals, kinds.KindPage)
 
        for {
                if prevPage == nil {
                        break
                }
-               c.Assert(prevPage.Kind(), qt.Equals, page.KindPage)
+               c.Assert(prevPage.Kind(), qt.Equals, kinds.KindPage)
                prevPage = prevPage.Prev()
        }
 
        // Check bundles
        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(len(bundleFr.Resources()), qt.Equals, 1)
        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/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))
        b.AssertFileContent("public/en/bundles/b1/index.html", "RelPermalink: /blog/en/bundles/b1/|")
        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/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(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")
                                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(len(homeEn.Translations()), qt.Equals, 3)
                                c.Assert(homeEn.Translations()[0].Language().Lang, qt.Equals, "fr")
index 2aba5b593fe212556232e3032554287061ae3bee..a37310987f5afd56ec0eb62ccd7805975af3efba 100644 (file)
@@ -3,7 +3,7 @@ package hugolib
 import (
        "testing"
 
-       "github.com/gohugoio/hugo/resources/page"
+       "github.com/gohugoio/hugo/resources/kinds"
 
        qt "github.com/frankban/quicktest"
 )
@@ -58,7 +58,7 @@ languageName = "Nynorsk"
 
        s1 := b.H.Sites[0]
 
-       s1h := s1.getPage(page.KindHome)
+       s1h := s1.getPage(kinds.KindHome)
        c.Assert(s1h.IsTranslated(), qt.Equals, true)
        c.Assert(len(s1h.Translations()), qt.Equals, 2)
        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.
        //
        // 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.RelPermalink(), qt.Equals, "/docs/superbob/")
        b.AssertFileContent("public/en/superbob/index.html", "doc3|Hello|en")
@@ -86,7 +86,7 @@ languageName = "Nynorsk"
 
        s2 := b.H.Sites[1]
 
-       s2h := s2.getPage(page.KindHome)
+       s2h := s2.getPage(kinds.KindHome)
        c.Assert(s2h.Permalink(), qt.Equals, "https://example.fr/")
 
        // See https://github.com/gohugoio/hugo/issues/10912
@@ -104,7 +104,7 @@ languageName = "Nynorsk"
 
        // 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.RelPermalink(), qt.Equals, "/docs/bundles/b1/")
        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/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.RelPermalink(), qt.Equals, "/bundles/b1/")
        c.Assert(len(bundleFr.Resources()), qt.Equals, 1)
index 05e207bbc66fb0315029c61443441618cf7f3763..a22201475c0a2767ba13feb20c419165d2198a43 100644 (file)
@@ -20,10 +20,9 @@ import (
        "path/filepath"
        "testing"
 
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/spf13/cast"
 
-       "github.com/gohugoio/hugo/resources/page"
-
        qt "github.com/frankban/quicktest"
 )
 
@@ -312,7 +311,7 @@ Content.
        b.AssertFileContent("public/sv/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(len(nnSect.Pages()), qt.Equals, 12)
        nnHome := nnSite.Home()
index 2644c8e4e34ca3e7a3f910b6c2f9ad79a0279e27..f8f96615688609a122d45d70d096bda1fa3272e6 100644 (file)
@@ -49,6 +49,7 @@ import (
        "github.com/gohugoio/hugo/common/collections"
        "github.com/gohugoio/hugo/common/text"
        "github.com/gohugoio/hugo/resources"
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/gohugoio/hugo/resources/page"
        "github.com/gohugoio/hugo/resources/resource"
 )
@@ -249,7 +250,7 @@ func (p *pageState) RegularPagesRecursive() page.Pages {
        p.regularPagesRecursiveInit.Do(func() {
                var pages page.Pages
                switch p.Kind() {
-               case page.KindSection:
+               case kinds.KindSection:
                        pages = p.getPagesRecursive()
                default:
                        pages = p.RegularPages()
@@ -268,10 +269,10 @@ func (p *pageState) RegularPages() page.Pages {
                var pages page.Pages
 
                switch p.Kind() {
-               case page.KindPage:
-               case page.KindSection, page.KindHome, page.KindTaxonomy:
+               case kinds.KindPage:
+               case kinds.KindSection, kinds.KindHome, kinds.KindTaxonomy:
                        pages = p.getPages()
-               case page.KindTerm:
+               case kinds.KindTerm:
                        all := p.Pages()
                        for _, p := range all {
                                if p.IsPage() {
@@ -293,15 +294,15 @@ func (p *pageState) Pages() page.Pages {
                var pages page.Pages
 
                switch p.Kind() {
-               case page.KindPage:
-               case page.KindSection, page.KindHome:
+               case kinds.KindPage:
+               case kinds.KindSection, kinds.KindHome:
                        pages = p.getPagesAndSections()
-               case page.KindTerm:
+               case kinds.KindTerm:
                        b := p.treeRef.n
                        viewInfo := b.viewInfo
                        taxonomy := p.s.Taxonomies()[viewInfo.name.plural].Get(viewInfo.termKey)
                        pages = taxonomy.Pages()
-               case page.KindTaxonomy:
+               case kinds.KindTaxonomy:
                        pages = p.bucket.getTaxonomies()
                default:
                        pages = p.s.Pages()
@@ -439,11 +440,11 @@ func (p *pageState) getLayoutDescriptor() layouts.LayoutDescriptor {
                sections := p.SectionsEntries()
 
                switch p.Kind() {
-               case page.KindSection:
+               case kinds.KindSection:
                        if len(sections) > 0 {
                                section = sections[0]
                        }
-               case page.KindTaxonomy, page.KindTerm:
+               case kinds.KindTaxonomy, kinds.KindTerm:
                        b := p.getTreeRef().n
                        section = b.viewInfo.name.singular
                default:
index 19b0154ad16120a6602ba1b0d2e6c0ff905051ea..ad6ba126e4e0a19d3c9d80779f3a57bed9049b38 100644 (file)
@@ -16,6 +16,7 @@ package hugolib
 import (
        "sync"
 
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/gohugoio/hugo/resources/page"
 )
 
@@ -30,12 +31,12 @@ func (p *pageData) Data() any {
        p.dataInit.Do(func() {
                p.data = make(page.Data)
 
-               if p.Kind() == page.KindPage {
+               if p.Kind() == kinds.KindPage {
                        return
                }
 
                switch p.Kind() {
-               case page.KindTerm:
+               case kinds.KindTerm:
                        b := p.treeRef.n
                        name := b.viewInfo.name
                        termKey := b.viewInfo.termKey
@@ -46,7 +47,7 @@ func (p *pageData) Data() any {
                        p.data["Singular"] = name.singular
                        p.data["Plural"] = name.plural
                        p.data["Term"] = b.viewInfo.term()
-               case page.KindTaxonomy:
+               case kinds.KindTaxonomy:
                        b := p.treeRef.n
                        name := b.viewInfo.name
 
index 7ad2a8d51a516634ff487147b49df8e3959359ac..1c4f13d3bbe6ff99909faad5f7a95b15db3ece34 100644 (file)
@@ -40,6 +40,7 @@ import (
        "github.com/gohugoio/hugo/helpers"
 
        "github.com/gohugoio/hugo/output"
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/gohugoio/hugo/resources/page"
        "github.com/gohugoio/hugo/resources/page/pagemeta"
        "github.com/gohugoio/hugo/resources/resource"
@@ -164,7 +165,7 @@ func (p *pageMeta) File() source.File {
 }
 
 func (p *pageMeta) IsHome() bool {
-       return p.Kind() == page.KindHome
+       return p.Kind() == kinds.KindHome
 }
 
 func (p *pageMeta) Keywords() []string {
@@ -199,7 +200,7 @@ func (p *pageMeta) IsNode() 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,
@@ -251,7 +252,7 @@ func (p *pageMeta) RelatedKeywords(cfg related.IndexConfig) ([]related.Keyword,
 }
 
 func (p *pageMeta) IsSection() bool {
-       return p.Kind() == page.KindSection
+       return p.Kind() == kinds.KindSection
 }
 
 func (p *pageMeta) Section() string {
@@ -680,9 +681,9 @@ func (p *pageMeta) applyDefaultValues(n *contentNode) error {
 
        if p.title == "" && p.f.IsZero() {
                switch p.Kind() {
-               case page.KindHome:
+               case kinds.KindHome:
                        p.title = p.s.Title()
-               case page.KindSection:
+               case kinds.KindSection:
                        var sectionName string
                        if n != nil {
                                sectionName = n.rootSection()
@@ -696,13 +697,13 @@ func (p *pageMeta) applyDefaultValues(n *contentNode) error {
                        } else {
                                p.title = sectionName
                        }
-               case page.KindTerm:
+               case kinds.KindTerm:
                        // TODO(bep) improve
                        key := p.sections[len(p.sections)-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])
-               case kind404:
+               case kinds.Kind404:
                        p.title = "404 Page not found"
 
                }
index 2ec89561cbe499db5a9af4b78ee8d23ef443444a..6a1b4bfab81796d417e78114642833e247a3e9a1 100644 (file)
@@ -17,6 +17,7 @@ import (
        "sync"
 
        "github.com/gohugoio/hugo/common/herrors"
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/gohugoio/hugo/resources/page"
 )
 
@@ -86,12 +87,12 @@ func (p *pagePaginator) Paginator(options ...any) (*page.Pager, error) {
                var pages page.Pages
 
                switch p.source.Kind() {
-               case page.KindHome:
+               case kinds.KindHome:
                        // From Hugo 0.57 we made home.Pages() work like any other
                        // section. To avoid the default paginators for the home page
                        // changing in the wild, we make this a special case.
                        pages = p.source.s.RegularPages()
-               case page.KindTerm, page.KindTaxonomy:
+               case kinds.KindTerm, kinds.KindTaxonomy:
                        pages = p.source.Pages()
                default:
                        pages = p.source.RegularPages()
index a834a1d9d7ddd2ee0a560a12f43eab7dc2d2b122..9a6caa05e0b9b3457c43d50a6a002d2bbae9190d 100644 (file)
@@ -20,6 +20,7 @@ import (
        "github.com/gohugoio/hugo/helpers"
        "github.com/gohugoio/hugo/hugofs/files"
 
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/gohugoio/hugo/resources/page"
 )
 
@@ -125,7 +126,7 @@ func createTargetPathDescriptor(s *Site, p page.Page, pm *pageMeta) (page.Target
                baseName = contentBaseName
        }
 
-       alwaysInSubDir := p.Kind() == kindSitemap
+       alwaysInSubDir := p.Kind() == kinds.KindSitemap
 
        desc := page.TargetPathDescriptor{
                PathSpec:    d.PathSpec,
index 2f9fd2e4681d9d4c51965dbed85ee3199f5732c5..8b02667f18c27e77a0bc3b431be0b35ff6f6be88 100644 (file)
@@ -18,6 +18,7 @@ import (
        "strings"
 
        "github.com/gohugoio/hugo/common/types"
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/gohugoio/hugo/resources/page"
 )
 
@@ -166,7 +167,7 @@ func (pt pageTree) Parent() page.Page {
 
        tree := p.getTreeRef()
 
-       if tree == nil || pt.p.Kind() == page.KindTaxonomy {
+       if tree == nil || pt.p.Kind() == kinds.KindTaxonomy {
                return pt.p.s.home
        }
 
index 6536ad6bb0ab85fe703830e2e00823c3d017d7c8..9bdf689d784398aa5a24e480f0ff1b0bbcf2d0f1 100644 (file)
 
 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 (
-
-       // 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"
 )
-
-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)]
-}
index ebf5d628bd1d6f89c8af1079843b0abda861881d..64d3298328547f37347b07f8343ef4196fb1cab5 100644 (file)
@@ -34,6 +34,7 @@ import (
 
        "github.com/gohugoio/hugo/hugofs"
 
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/gohugoio/hugo/resources/page"
 
        "github.com/gohugoio/hugo/htesting"
@@ -104,7 +105,7 @@ func TestPageBundlerSiteRegular(t *testing.T) {
 
                                                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, qt.Not(qt.IsNil))
@@ -150,18 +151,18 @@ func TestPageBundlerSiteRegular(t *testing.T) {
                                                // This should be just copied to destination.
                                                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.BundleType(), qt.Equals, files.ContentClassLeaf)
                                                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))
                                                home := s.Home()
                                                c.Assert(home.BundleType(), qt.Equals, files.ContentClassBranch)
 
                                                // This is a root bundle and should live in the "home section"
                                                // 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.Parent().IsHome(), qt.Equals, true)
                                                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/")
                                                }
 
-                                               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))
-                                               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))
 
                                                pageResources := leafBundle1.Resources().ByType(pageResourceType)
@@ -302,7 +303,7 @@ func TestPageBundlerSiteMultilingual(t *testing.T) {
 
                                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))
 
                                // 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")
                                // These may also be translated, so we also need to test that.
                                //  "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.Language().Lang, qt.Equals, "en")
-                               c.Assert(s.getPage(page.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(page.KindPage, "my-bf-bundle"), qt.Equals, bfBundle)
+                               c.Assert(s.getPage(kinds.KindPage, "bf/my-bf-bundle/index.md"), qt.Equals, bfBundle)
+                               c.Assert(s.getPage(kinds.KindPage, "bf/my-bf-bundle"), qt.Equals, bfBundle)
+                               c.Assert(s.getPage(kinds.KindPage, "my-bf-bundle"), qt.Equals, bfBundle)
 
                                nnSite := sites.Sites[1]
                                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.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(page.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, "bf/my-bf-bundle/index.nn.md"), qt.Equals, bfBundleNN)
+                               c.Assert(nnSite.getPage(kinds.KindPage, "bf/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
                                // Every resource should have its Name prefixed with its base folder.
@@ -483,7 +484,7 @@ TheContent.
        s := b.H.Sites[0]
 
        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(len(a1Bundle.Resources()), qt.Equals, 2)
        c.Assert(len(a1Bundle.Resources().ByType(pageResourceType)), qt.Equals, 1)
@@ -543,10 +544,10 @@ HEADLESS {{< myShort >}}
 
        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/")
 
-       headless := s.getPage(page.KindPage, "b/index")
+       headless := s.getPage(kinds.KindPage, "b/index")
        c.Assert(headless, qt.Not(qt.IsNil))
        c.Assert(headless.Title(), qt.Equals, "Headless Bundle in Topless Bar")
        c.Assert(headless.RelPermalink(), qt.Equals, "")
index b49669bb66c67cd1abc03afe39a275343bd3c490..26da4905e801dc4362b2b5d6bfffed7c3e98d3dc 100644 (file)
@@ -26,6 +26,7 @@ import (
 
        "github.com/gohugoio/hugo/helpers"
 
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/gohugoio/hugo/resources/page"
 )
 
@@ -92,7 +93,7 @@ func newPageCollections(m *pageMap) *PageCollections {
        })
 
        c.regularPages = newLazyPagesFactory(func() page.Pages {
-               return c.findPagesByKindIn(page.KindPage, c.pages.get())
+               return c.findPagesByKindIn(kinds.KindPage, c.pages.get())
        })
 
        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)
        }
 
-       if len(refs) == 0 || refs[0] == page.KindHome {
+       if len(refs) == 0 || refs[0] == kinds.KindHome {
                key = "/"
        } 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".
                        // Typically fetched via {{ .Site.GetPage "section" .Section }}
                        // See https://github.com/gohugoio/hugo/issues/4989
index 66f157781951d4f6e4437203e0fa48db888dd277..1be2962621c4fd0d0bbf7bd7adbdfac64bb08178 100644 (file)
@@ -22,6 +22,7 @@ import (
        "time"
 
        qt "github.com/frankban/quicktest"
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/gohugoio/hugo/resources/page"
 
        "github.com/gohugoio/hugo/deps"
@@ -231,72 +232,72 @@ func TestGetPage(t *testing.T) {
 
        tests := []getPageTest{
                // legacy content root relative paths
-               {"Root relative, no slash, home", page.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, section", page.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, sub section", page.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, OS slashes", page.KindPage, nil, []string{filepath.FromSlash("sect5/page3.md")}, "Title5_3"},
-
-               {"Short ref, unique", page.KindPage, nil, []string{"unique.md", "unique"}, "UniqueBase"},
-               {"Short ref, unique, upper case", page.KindPage, nil, []string{"Unique2.md", "unique2.md", "unique2"}, "UniqueBase2"},
+               {"Root relative, no slash, home", kinds.KindHome, nil, []string{""}, "home page"},
+               {"Root relative, no slash, root page", kinds.KindPage, nil, []string{"about.md", "ABOUT.md"}, "about page"},
+               {"Root relative, no slash, section", kinds.KindSection, nil, []string{"sect3"}, "section 3"},
+               {"Root relative, no slash, section page", kinds.KindPage, nil, []string{"sect3/page1.md"}, "Title3_1"},
+               {"Root relative, no slash, sub section", kinds.KindSection, nil, []string{"sect3/sect7"}, "another sect7"},
+               {"Root relative, no slash, nested page", kinds.KindPage, nil, []string{"sect3/subsect/deep.md"}, "deep page"},
+               {"Root relative, no slash, OS slashes", kinds.KindPage, nil, []string{filepath.FromSlash("sect5/page3.md")}, "Title5_3"},
+
+               {"Short ref, unique", kinds.KindPage, nil, []string{"unique.md", "unique"}, "UniqueBase"},
+               {"Short ref, unique, upper case", kinds.KindPage, nil, []string{"Unique2.md", "unique2.md", "unique2"}, "UniqueBase2"},
                {"Short ref, ambiguous", "Ambiguous", nil, []string{"page1.md"}, ""},
 
                // ISSUE: This is an ambiguous ref, but because we have to support the legacy
                // content root relative paths without a leading slash, the lookup
                // returns /sect7. This undermines ambiguity detection, but we have no choice.
                //{"Ambiguous", nil, []string{"sect7"}, ""},
-               {"Section, ambiguous", page.KindSection, nil, []string{"sect7"}, "Sect7s"},
-
-               {"Absolute, home", page.KindHome, nil, []string{"/", ""}, "home page"},
-               {"Absolute, page", page.KindPage, nil, []string{"/about.md", "/about"}, "about page"},
-               {"Absolute, sect", page.KindSection, nil, []string{"/sect3"}, "section 3"},
-               {"Absolute, page in subsection", page.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, page, deep", page.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, unique", page.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"},
+               {"Section, ambiguous", kinds.KindSection, nil, []string{"sect7"}, "Sect7s"},
+
+               {"Absolute, home", kinds.KindHome, nil, []string{"/", ""}, "home page"},
+               {"Absolute, page", kinds.KindPage, nil, []string{"/about.md", "/about"}, "about page"},
+               {"Absolute, sect", kinds.KindSection, nil, []string{"/sect3"}, "section 3"},
+               {"Absolute, page in subsection", kinds.KindPage, nil, []string{"/sect3/page1.md", "/Sect3/Page1.md"}, "Title3_1"},
+               {"Absolute, section, subsection with same name", kinds.KindSection, nil, []string{"/sect3/sect7"}, "another sect7"},
+               {"Absolute, page, deep", kinds.KindPage, nil, []string{"/sect3/subsect/deep.md"}, "deep page"},
+               {"Absolute, page, OS slashes", kinds.KindPage, nil, []string{filepath.FromSlash("/sect5/page3.md")}, "Title5_3"}, // test OS-specific path
+               {"Absolute, unique", kinds.KindPage, nil, []string{"/sect3/unique.md"}, "UniqueBase"},
+               {"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
                // {"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 section", "NoPage", nil, []string{"/missing-section"}, ""},
 
                // relative paths
-               {"Dot relative, home", page.KindHome, sec3, []string{".."}, "home page"},
-               {"Dot relative, home, slash", page.KindHome, sec3, []string{"../"}, "home page"},
-               {"Dot relative about", page.KindPage, sec3, []string{"../about.md"}, "about page"},
-               {"Dot", page.KindSection, sec3, []string{"."}, "section 3"},
-               {"Dot slash", page.KindSection, sec3, []string{"./"}, "section 3"},
-               {"Page relative, no dot", page.KindPage, sec3, []string{"page1.md"}, "Title3_1"},
-               {"Page relative, dot", page.KindPage, sec3, []string{"./page1.md"}, "Title3_1"},
-               {"Up and down another section", page.KindPage, sec3, []string{"../sect4/page2.md"}, "Title4_2"},
-               {"Rel sect7", page.KindSection, sec3, []string{"sect7"}, "another sect7"},
-               {"Rel sect7 dot", page.KindSection, sec3, []string{"./sect7"}, "another sect7"},
-               {"Dot deep", page.KindPage, sec3, []string{"./subsect/deep.md"}, "deep page"},
-               {"Dot dot inner", page.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 unique", page.KindPage, sec3, []string{"./unique.md"}, "UniqueBase"},
+               {"Dot relative, home", kinds.KindHome, sec3, []string{".."}, "home page"},
+               {"Dot relative, home, slash", kinds.KindHome, sec3, []string{"../"}, "home page"},
+               {"Dot relative about", kinds.KindPage, sec3, []string{"../about.md"}, "about page"},
+               {"Dot", kinds.KindSection, sec3, []string{"."}, "section 3"},
+               {"Dot slash", kinds.KindSection, sec3, []string{"./"}, "section 3"},
+               {"Page relative, no dot", kinds.KindPage, sec3, []string{"page1.md"}, "Title3_1"},
+               {"Page relative, dot", kinds.KindPage, sec3, []string{"./page1.md"}, "Title3_1"},
+               {"Up and down another section", kinds.KindPage, sec3, []string{"../sect4/page2.md"}, "Title4_2"},
+               {"Rel sect7", kinds.KindSection, sec3, []string{"sect7"}, "another sect7"},
+               {"Rel sect7 dot", kinds.KindSection, sec3, []string{"./sect7"}, "another sect7"},
+               {"Dot deep", kinds.KindPage, sec3, []string{"./subsect/deep.md"}, "deep page"},
+               {"Dot dot inner", kinds.KindPage, sec3, []string{"./subsect/../../sect7/page9.md"}, "Title7_9"},
+               {"Dot OS slash", kinds.KindPage, sec3, []string{filepath.FromSlash("../sect5/page3.md")}, "Title5_3"}, // test OS-specific path
+               {"Dot unique", kinds.KindPage, sec3, []string{"./unique.md"}, "UniqueBase"},
                {"Dot sect", "NoPage", sec3, []string{"./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, about", page.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 subsect deep", page.KindPage, sec3, []string{"/sect3/subsect/deep.md"}, "deep page"}, // next test depends on this page existing
+               {"Abs, ignore context, home", kinds.KindHome, sec3, []string{"/"}, "home page"},
+               {"Abs, ignore context, about", kinds.KindPage, sec3, []string{"/about.md"}, "about page"},
+               {"Abs, ignore context, page in section", kinds.KindPage, sec3, []string{"/sect4/page2.md"}, "Title4_2"},
+               {"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"}, ""},
 
                // Taxonomies
-               {"Taxonomy term", page.KindTaxonomy, nil, []string{"categories"}, "Categories"},
-               {"Taxonomy", page.KindTerm, nil, []string{"categories/hugo", "categories/Hugo"}, "Hugo"},
+               {"Taxonomy term", kinds.KindTaxonomy, nil, []string{"categories"}, "Categories"},
+               {"Taxonomy", kinds.KindTerm, nil, []string{"categories/hugo", "categories/Hugo"}, "Hugo"},
 
                // Bundle variants
-               {"Bundle regular", page.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 regular", kinds.KindPage, nil, []string{"sect3/b1", "sect3/b1/index.md", "sect3/b1/index.en.md"}, "b1 bundle"},
+               {"Bundle index name", kinds.KindPage, nil, []string{"sect3/index/index.md", "sect3/index"}, "index bundle"},
 
                // 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 {
index a95b3896772685c6e5c5b86c3e19780687fb8eac..774794c56f6048be0f26d2fcc622b4401d04b5c8 100644 (file)
@@ -22,9 +22,9 @@ import (
        "testing"
 
        "github.com/gohugoio/hugo/config"
+       "github.com/gohugoio/hugo/resources/kinds"
 
        "github.com/gohugoio/hugo/parser/pageparser"
-       "github.com/gohugoio/hugo/resources/page"
 
        qt "github.com/frankban/quicktest"
 )
@@ -186,7 +186,7 @@ CSV: {{< myShort >}}
        b.Assert(len(h.Sites), qt.Equals, 1)
 
        s := h.Sites[0]
-       home := s.getPage(page.KindHome)
+       home := s.getPage(kinds.KindHome)
        b.Assert(home, qt.Not(qt.IsNil))
        b.Assert(len(home.OutputFormats()), qt.Equals, 3)
 
index b5c43fba3c216cd138d8503119f2d9948dde69a5..863b5c4b7a22a738b548eec04d7d48d68bbadfb1 100644 (file)
@@ -52,6 +52,7 @@ import (
 
        "github.com/gohugoio/hugo/langs"
 
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/gohugoio/hugo/resources/page"
 
        "github.com/gohugoio/hugo/config"
@@ -248,7 +249,7 @@ func (s *Site) initRenderFormats() {
        })
 
        // 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 {
                        for _, f := range siteFormats {
                                if !formatSet[f.Name] {
@@ -276,9 +277,6 @@ func (s *Site) Languages() langs.Languages {
 }
 
 func (s *Site) isEnabled(kind string) bool {
-       if kind == kindUnknown {
-               panic("Unknown 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 {
        if fi.TranslationBaseName() == "_index" {
                if fi.Dir() == "" {
-                       return page.KindHome
+                       return kinds.KindHome
                }
 
                return s.kindFromSections(sections)
 
        }
 
-       return page.KindPage
+       return kinds.KindPage
 }
 
 func (s *Site) kindFromSections(sections []string) string {
        if len(sections) == 0 {
-               return page.KindHome
+               return kinds.KindHome
        }
 
        return s.kindFromSectionPath(path.Join(sections...))
@@ -1163,16 +1161,16 @@ func (s *Site) kindFromSectionPath(sectionPath string) string {
        var taxonomiesConfig taxonomiesConfig = s.conf.Taxonomies
        for _, plural := range taxonomiesConfig {
                if plural == sectionPath {
-                       return page.KindTaxonomy
+                       return kinds.KindTaxonomy
                }
 
                if strings.HasPrefix(sectionPath, plural) {
-                       return page.KindTerm
+                       return kinds.KindTerm
                }
 
        }
 
-       return page.KindSection
+       return kinds.KindSection
 }
 
 func (s *Site) newPage(
index 61273d3c87475bd7c48d20c75cc102d51f3994e1..13c845376945615f73446e528eff7c8c5b4a1811 100644 (file)
@@ -40,6 +40,7 @@ import (
        "github.com/gohugoio/hugo/navigation"
        "github.com/gohugoio/hugo/output"
        "github.com/gohugoio/hugo/publisher"
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/gohugoio/hugo/resources/page"
        "github.com/gohugoio/hugo/resources/page/pagemeta"
        "github.com/gohugoio/hugo/resources/resource"
@@ -185,9 +186,9 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) {
                        contentMap: newContentMap(contentMapConfig{
                                lang:                 k,
                                taxonomyConfig:       taxonomiesConfig.Values(),
-                               taxonomyDisabled:     !conf.IsKindEnabled(page.KindTerm),
-                               taxonomyTermDisabled: !conf.IsKindEnabled(page.KindTaxonomy),
-                               pageDisabled:         !conf.IsKindEnabled(page.KindPage),
+                               taxonomyDisabled:     !conf.IsKindEnabled(kinds.KindTerm),
+                               taxonomyTermDisabled: !conf.IsKindEnabled(kinds.KindTaxonomy),
+                               pageDisabled:         !conf.IsKindEnabled(kinds.KindPage),
                        }),
                        s: s,
                }
index 1e248baffe2984ce1bf4b7cdc52fbca8eae36e17..d6f55cbdd9bdf424d6ca185bf3989c39877dedf6 100644 (file)
@@ -18,7 +18,7 @@ import (
        "strings"
 
        "github.com/gohugoio/hugo/output"
-       "github.com/gohugoio/hugo/resources/page"
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/spf13/cast"
 )
 
@@ -34,20 +34,20 @@ func createDefaultOutputFormats(allFormats output.Formats) map[string]output.For
        }
 
        m := map[string]output.Formats{
-               page.KindPage:     {htmlOut},
-               page.KindHome:     defaultListTypes,
-               page.KindSection:  defaultListTypes,
-               page.KindTerm:     defaultListTypes,
-               page.KindTaxonomy: defaultListTypes,
+               kinds.KindPage:     {htmlOut},
+               kinds.KindHome:     defaultListTypes,
+               kinds.KindSection:  defaultListTypes,
+               kinds.KindTerm:     defaultListTypes,
+               kinds.KindTaxonomy: defaultListTypes,
                // Below are for consistency. They are currently not used during rendering.
-               kindSitemap:   {sitemapOut},
-               kindRobotsTXT: {robotsOut},
-               kind404:       {htmlOut},
+               kinds.KindSitemap:   {sitemapOut},
+               kinds.KindRobotsTXT: {robotsOut},
+               kinds.Kind404:       {htmlOut},
        }
 
        // May be disabled
        if rssFound {
-               m[kindRSS] = output.Formats{rssOut}
+               m[kinds.KindRSS] = output.Formats{rssOut}
        }
 
        return m
@@ -69,7 +69,7 @@ func createSiteOutputFormats(allFormats output.Formats, outputs map[string]any,
        seen := make(map[string]bool)
 
        for k, v := range outputs {
-               k = getKind(k)
+               k = kinds.GetKindAny(k)
                if k == "" {
                        // Invalid kind
                        continue
index b598e23d61d8f9d3b46a2a381cdfe0f16f332ea9..ce415a8242f4f642c5597beb60a87cab8caf8ba2 100644 (file)
@@ -21,7 +21,7 @@ import (
 
        qt "github.com/frankban/quicktest"
        "github.com/gohugoio/hugo/config"
-       "github.com/gohugoio/hugo/resources/page"
+       "github.com/gohugoio/hugo/resources/kinds"
 
        "github.com/spf13/afero"
 
@@ -142,7 +142,7 @@ Len Pages: {{ .Kind }} {{ len .Site.RegularPages }} Page Number: {{ .Paginator.P
        s := b.H.Sites[0]
        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))
 
@@ -314,7 +314,7 @@ baseName = "customdelimbase"
        th.assertFileContent("public/nosuffixbase", "no suffix")
        th.assertFileContent("public/customdelimbase_del", "custom delim")
 
-       home := s.getPage(page.KindHome)
+       home := s.getPage(kinds.KindHome)
        c.Assert(home, qt.Not(qt.IsNil))
 
        outputs := home.OutputFormats()
@@ -360,8 +360,8 @@ func TestCreateSiteOutputFormats(t *testing.T) {
                c := qt.New(t)
 
                outputsConfig := map[string]any{
-                       page.KindHome:    []string{"HTML", "JSON"},
-                       page.KindSection: []string{"JSON"},
+                       kinds.KindHome:    []string{"HTML", "JSON"},
+                       kinds.KindSection: []string{"JSON"},
                }
 
                cfg := config.New()
@@ -369,21 +369,21 @@ func TestCreateSiteOutputFormats(t *testing.T) {
 
                outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false)
                c.Assert(err, qt.IsNil)
-               c.Assert(outputs[page.KindSection], deepEqualsOutputFormats, output.Formats{output.JSONFormat})
-               c.Assert(outputs[page.KindHome], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.JSONFormat})
+               c.Assert(outputs[kinds.KindSection], deepEqualsOutputFormats, output.Formats{output.JSONFormat})
+               c.Assert(outputs[kinds.KindHome], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.JSONFormat})
 
                // Defaults
-               c.Assert(outputs[page.KindTerm], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat})
-               c.Assert(outputs[page.KindTaxonomy], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat})
-               c.Assert(outputs[page.KindPage], deepEqualsOutputFormats, output.Formats{output.HTMLFormat})
+               c.Assert(outputs[kinds.KindTerm], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat})
+               c.Assert(outputs[kinds.KindTaxonomy], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat})
+               c.Assert(outputs[kinds.KindPage], deepEqualsOutputFormats, output.Formats{output.HTMLFormat})
 
                // These aren't (currently) in use when rendering in Hugo,
                // but the pages needs to be assigned an output format,
                // so these should also be correct/sensible.
-               c.Assert(outputs[kindRSS], deepEqualsOutputFormats, output.Formats{output.RSSFormat})
-               c.Assert(outputs[kindSitemap], deepEqualsOutputFormats, output.Formats{output.SitemapFormat})
-               c.Assert(outputs[kindRobotsTXT], deepEqualsOutputFormats, output.Formats{output.RobotsTxtFormat})
-               c.Assert(outputs[kind404], deepEqualsOutputFormats, output.Formats{output.HTMLFormat})
+               c.Assert(outputs[kinds.KindRSS], deepEqualsOutputFormats, output.Formats{output.RSSFormat})
+               c.Assert(outputs[kinds.KindSitemap], deepEqualsOutputFormats, output.Formats{output.SitemapFormat})
+               c.Assert(outputs[kinds.KindRobotsTXT], deepEqualsOutputFormats, output.Formats{output.RobotsTxtFormat})
+               c.Assert(outputs[kinds.Kind404], deepEqualsOutputFormats, output.Formats{output.HTMLFormat})
        })
 
        // Issue #4528
@@ -400,7 +400,7 @@ func TestCreateSiteOutputFormats(t *testing.T) {
 
                outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false)
                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)
 
        outputsConfig := map[string]any{
-               page.KindHome: []string{"FOO", "JSON"},
+               kinds.KindHome: []string{"FOO", "JSON"},
        }
 
        cfg := config.New()
@@ -422,7 +422,7 @@ func TestCreateSiteOutputFormatsEmptyConfig(t *testing.T) {
        c := qt.New(t)
 
        outputsConfig := map[string]any{
-               page.KindHome: []string{},
+               kinds.KindHome: []string{},
        }
 
        cfg := config.New()
@@ -430,14 +430,14 @@ func TestCreateSiteOutputFormatsEmptyConfig(t *testing.T) {
 
        outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false)
        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) {
        c := qt.New(t)
 
        outputsConfig := map[string]any{
-               page.KindHome: []string{},
+               kinds.KindHome: []string{},
        }
 
        cfg := config.New()
@@ -450,7 +450,7 @@ func TestCreateSiteOutputFormatsCustomFormats(t *testing.T) {
 
        outputs, err := createSiteOutputFormats(output.Formats{customRSS, customHTML}, cfg.GetStringMap("outputs"), false)
        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
index f9c1dd498c49bf0a6ff9689ae46be2337664615a..43371b44da92635626795e4e24f7119a5b9462c5 100644 (file)
@@ -29,6 +29,7 @@ import (
 
        "github.com/gohugoio/hugo/output"
 
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/gohugoio/hugo/resources/page"
        "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 {
        p, err := newPageStandalone(&pageMeta{
                s:    s,
-               kind: kind404,
+               kind: kinds.Kind404,
                urlPaths: pagemeta.URLPath{
                        URL: "404.html",
                },
@@ -244,7 +245,7 @@ func (s *Site) render404() error {
        }
 
        var d layouts.LayoutDescriptor
-       d.Kind = kind404
+       d.Kind = kinds.Kind404
 
        templ, found, err := s.Tmpl().LookupLayout(d, output.HTMLFormat)
        if err != nil {
@@ -266,7 +267,7 @@ func (s *Site) render404() error {
 func (s *Site) renderSitemap() error {
        p, err := newPageStandalone(&pageMeta{
                s:    s,
-               kind: kindSitemap,
+               kind: kinds.KindSitemap,
                urlPaths: pagemeta.URLPath{
                        URL: s.conf.Sitemap.Filename,
                },
@@ -294,13 +295,13 @@ func (s *Site) renderSitemap() error {
 }
 
 func (s *Site) renderRobotsTXT() error {
-       if !s.conf.EnableRobotsTXT && s.isEnabled(kindRobotsTXT) {
+       if !s.conf.EnableRobotsTXT && s.isEnabled(kinds.KindRobotsTXT) {
                return nil
        }
 
        p, err := newPageStandalone(&pageMeta{
                s:    s,
-               kind: kindRobotsTXT,
+               kind: kinds.KindRobotsTXT,
                urlPaths: pagemeta.URLPath{
                        URL: "robots.txt",
                },
index 5c97163cb82ea9e6e81aadb80cc9b09252cf6c5e..f5cb41d28fbd5a498086dda8f8f3a64ec93855d2 100644 (file)
@@ -21,6 +21,7 @@ import (
 
        qt "github.com/frankban/quicktest"
        "github.com/gohugoio/hugo/deps"
+       "github.com/gohugoio/hugo/resources/kinds"
        "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 {
                test := test
@@ -301,7 +302,7 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
                        t.Parallel()
                        c := qt.New(t)
                        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)))
 
                        if p.Pages() != nil {
@@ -318,7 +319,7 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
        c.Assert(len(home.Sections()), qt.Equals, 9)
        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.Parent().IsHome(), qt.Equals, true)
        // 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
        // getPage.
        // 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.RelPermalink(), qt.Equals, "/spaces-in-section/")
 
index effdac6df91dc62b66880c9670b27b5e5eadc635..f4d63943f6b56937661520aec02579490e37eb3b 100644 (file)
@@ -28,6 +28,7 @@ import (
 
        qt "github.com/frankban/quicktest"
        "github.com/gohugoio/hugo/deps"
+       "github.com/gohugoio/hugo/resources/kinds"
        "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})
 
-       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.")
        }
 
@@ -1010,7 +1011,7 @@ func TestRefLinking(t *testing.T) {
        t.Parallel()
        site := setupLinkingMockSite(t)
 
-       currentPage := site.getPage(page.KindPage, "level2/level3/start.md")
+       currentPage := site.getPage(kinds.KindPage, "level2/level3/start.md")
        if currentPage == nil {
                t.Fatalf("failed to find current page in site")
        }
index 821c84c95130e58613e3ecc9569ccdf5c3f69c58..fd15eb5d32e40121d338581096c6bc51494cf178 100644 (file)
@@ -18,10 +18,9 @@ import (
        "path/filepath"
        "testing"
 
-       "github.com/gohugoio/hugo/resources/page"
-
        qt "github.com/frankban/quicktest"
        "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"
@@ -68,12 +67,12 @@ Do not go gentle into that good night.
 
        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.Section(), qt.Equals, "sect1")
        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.Section(), qt.Equals, "sect2")
        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)
 
-       sect1 := s.getPage(page.KindSection, "sect1")
+       sect1 := s.getPage(kinds.KindSection, "sect1")
        c.Assert(sect1, qt.Not(qt.IsNil))
        c.Assert(sect1.RelPermalink(), qt.Equals, "/ss1/")
        th.assertFileContent(filepath.Join("public", "ss1", "index.html"), "P1|URL: /ss1/|Next: /ss1/page/2/")
index 94e937c81cca8fb2a6f4059a56f221e234ebec1a..d4ded2058584122812dcf3626be1ea840af06391 100644 (file)
@@ -20,6 +20,7 @@ import (
        "strings"
        "testing"
 
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/gohugoio/hugo/resources/page"
 
        qt "github.com/frankban/quicktest"
@@ -155,8 +156,8 @@ permalinkeds:
 
        s := b.H.Sites[0]
 
-       // Make sure that each page.KindTaxonomyTerm page has an appropriate number
-       // of page.KindTaxonomy pages in its Pages slice.
+       // Make sure that each kinds.KindTaxonomyTerm page has an appropriate number
+       // of kinds.KindTaxonomy pages in its Pages slice.
        taxonomyTermPageCounts := map[string]int{
                "tags":         3,
                "categories":   2,
@@ -167,16 +168,16 @@ permalinkeds:
 
        for taxonomy, count := range taxonomyTermPageCounts {
                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(len(term.Pages()), qt.Equals, count, msg)
 
                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))
        if uglyURLs {
                b.Assert(cat1.RelPermalink(), qt.Equals, "/blog/categories/cat1.html")
@@ -184,8 +185,8 @@ permalinkeds:
                b.Assert(cat1.RelPermalink(), qt.Equals, "/blog/categories/cat1/")
        }
 
-       pl1 := s.getPage(page.KindTerm, "permalinkeds", "pl1")
-       permalinkeds := s.getPage(page.KindTaxonomy, "permalinkeds")
+       pl1 := s.getPage(kinds.KindTerm, "permalinkeds", "pl1")
+       permalinkeds := s.getPage(kinds.KindTaxonomy, "permalinkeds")
        b.Assert(pl1, qt.Not(qt.IsNil))
        b.Assert(permalinkeds, qt.Not(qt.IsNil))
        if uglyURLs {
@@ -196,7 +197,7 @@ 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.Title(), qt.Equals, "Hello Hugo world")
 
@@ -268,8 +269,8 @@ title: "This is S3s"
                return pages
        }
 
-       ta := filterbyKind(page.KindTerm)
-       te := filterbyKind(page.KindTaxonomy)
+       ta := filterbyKind(kinds.KindTerm)
+       te := filterbyKind(kinds.KindTaxonomy)
 
        b.Assert(len(te), qt.Equals, 4)
        b.Assert(len(ta), qt.Equals, 7)
diff --git a/resources/kinds/kinds.go b/resources/kinds/kinds.go
new file mode 100644 (file)
index 0000000..b1d1c18
--- /dev/null
@@ -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
+       }
+}
diff --git a/resources/kinds/kinds_test.go b/resources/kinds/kinds_test.go
new file mode 100644 (file)
index 0000000..c2868d6
--- /dev/null
@@ -0,0 +1,40 @@
+// 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 (
+       "testing"
+
+       qt "github.com/frankban/quicktest"
+)
+
+func TestKind(t *testing.T) {
+       t.Parallel()
+       c := qt.New(t)
+       // Add tests for these constants to make sure they don't change
+       c.Assert(KindPage, qt.Equals, "page")
+       c.Assert(KindHome, qt.Equals, "home")
+       c.Assert(KindSection, qt.Equals, "section")
+       c.Assert(KindTaxonomy, qt.Equals, "taxonomy")
+       c.Assert(KindTerm, qt.Equals, "term")
+
+       c.Assert(GetKindMain("TAXONOMYTERM"), qt.Equals, KindTaxonomy)
+       c.Assert(GetKindMain("Taxonomy"), qt.Equals, KindTaxonomy)
+       c.Assert(GetKindMain("Page"), qt.Equals, KindPage)
+       c.Assert(GetKindMain("Home"), qt.Equals, KindHome)
+       c.Assert(GetKindMain("SEction"), qt.Equals, KindSection)
+
+       c.Assert(GetKindAny("Page"), qt.Equals, KindPage)
+       c.Assert(GetKindAny("Robotstxt"), qt.Equals, KindRobotsTXT)
+}
index 47985984111d5abebcfed9c654d8a41f49a98080..bb846ca5b9d1cd00f5f2a58d5d6eb6e7c220dbb3 100644 (file)
 // limitations under the License.
 
 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)]
-}
diff --git a/resources/page/page_kinds_test.go b/resources/page/page_kinds_test.go
deleted file mode 100644 (file)
index 357be67..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2019 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 page
-
-import (
-       "testing"
-
-       qt "github.com/frankban/quicktest"
-)
-
-func TestKind(t *testing.T) {
-       t.Parallel()
-       c := qt.New(t)
-       // Add tests for these constants to make sure they don't change
-       c.Assert(KindPage, qt.Equals, "page")
-       c.Assert(KindHome, qt.Equals, "home")
-       c.Assert(KindSection, qt.Equals, "section")
-       c.Assert(KindTaxonomy, qt.Equals, "taxonomy")
-       c.Assert(KindTerm, qt.Equals, "term")
-
-       c.Assert(GetKind("TAXONOMYTERM"), qt.Equals, KindTaxonomy)
-       c.Assert(GetKind("Taxonomy"), qt.Equals, KindTaxonomy)
-       c.Assert(GetKind("Page"), qt.Equals, KindPage)
-       c.Assert(GetKind("Home"), qt.Equals, KindHome)
-       c.Assert(GetKind("SEction"), qt.Equals, KindSection)
-}
index a2b327f61094062f84c1fcf5f4c6ffb6a74b0c2d..4c861cbd7e3c70951b75218d1f63f3d4a91621a1 100644 (file)
@@ -21,6 +21,7 @@ import (
        "github.com/gohugoio/hugo/common/maps"
        "github.com/gohugoio/hugo/config"
        "github.com/gohugoio/hugo/hugofs/glob"
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/mitchellh/mapstructure"
 )
 
@@ -173,7 +174,7 @@ func decodePageMatcher(m any, v *PageMatcher) error {
        if v.Kind != "" {
                g, _ := glob.GetGlob(v.Kind)
                found := false
-               for _, k := range kindMap {
+               for _, k := range kinds.AllKindsInPages {
                        if g.Match(k) {
                                found = true
                                break
index 0ed758ca12a051291f37d6df2cb654a84b7f90cc..1bc16fe3550078e9800fad75f46bdee824ec4ee7 100644 (file)
@@ -21,6 +21,7 @@ import (
        "github.com/gohugoio/hugo/common/urls"
        "github.com/gohugoio/hugo/helpers"
        "github.com/gohugoio/hugo/output"
+       "github.com/gohugoio/hugo/resources/kinds"
 )
 
 const slash = "/"
@@ -147,7 +148,7 @@ func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths) {
                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 != "" {
                        pagePath = pjoin(pagePath, d.ExpandedPermalink)
                } else {
@@ -160,7 +161,7 @@ func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths) {
                pagePath = pjoin(pagePath, d.Type.Path)
        }
 
-       if d.Kind != KindHome && d.URL != "" {
+       if d.Kind != kinds.KindHome && d.URL != "" {
                pagePath = pjoin(pagePath, d.URL)
 
                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 != "" {
                        pagePath = pjoin(pagePath, d.ExpandedPermalink)
@@ -307,7 +308,7 @@ func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths) {
 
        // if page URL is explicitly set in frontmatter,
        // 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
                // disablePathToLower isn't set.
                pagePath = d.PathSpec.MakePathSanitized(pagePath)
index 137f3bec32f843d123ff21c89f47e3eb3067362a..dd6457f7738bbf2bd8a60677300fe839ea5f0016 100644 (file)
@@ -20,6 +20,7 @@ import (
        "testing"
 
        "github.com/gohugoio/hugo/media"
+       "github.com/gohugoio/hugo/resources/kinds"
        "github.com/gohugoio/hugo/resources/page"
 
        "github.com/gohugoio/hugo/output"
@@ -47,31 +48,31 @@ func TestPageTargetPath(t *testing.T) {
                                        d        page.TargetPathDescriptor
                                        expected page.TargetPaths
                                }{
-                                       {"JSON home", page.TargetPathDescriptor{Kind: page.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/"}},
-                                       {"HTML home", page.TargetPathDescriptor{Kind: page.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"}},
+                                       {"JSON home", page.TargetPathDescriptor{Kind: kinds.KindHome, Type: output.JSONFormat}, page.TargetPaths{TargetFilename: "/index.json", SubResourceBaseTarget: "", Link: "/index.json"}},
+                                       {"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: kinds.KindHome, BaseName: "_index", Type: output.HTMLFormat}, page.TargetPaths{TargetFilename: "/index.html", SubResourceBaseTarget: "", Link: "/"}},
+                                       {"Netlify redirects", page.TargetPathDescriptor{Kind: kinds.KindHome, BaseName: "_index", Type: noExtDelimFormat}, page.TargetPaths{TargetFilename: "/_redirects", SubResourceBaseTarget: "", Link: "/_redirects"}},
                                        {"HTML section list", page.TargetPathDescriptor{
-                                               Kind:     page.KindSection,
+                                               Kind:     kinds.KindSection,
                                                Sections: []string{"sect1"},
                                                BaseName: "_index",
                                                Type:     output.HTMLFormat,
                                        }, page.TargetPaths{TargetFilename: "/sect1/index.html", SubResourceBaseTarget: "/sect1", Link: "/sect1/"}},
                                        {"HTML taxonomy term", page.TargetPathDescriptor{
-                                               Kind:     page.KindTerm,
+                                               Kind:     kinds.KindTerm,
                                                Sections: []string{"tags", "hugo"},
                                                BaseName: "_index",
                                                Type:     output.HTMLFormat,
                                        }, page.TargetPaths{TargetFilename: "/tags/hugo/index.html", SubResourceBaseTarget: "/tags/hugo", Link: "/tags/hugo/"}},
                                        {"HTML taxonomy", page.TargetPathDescriptor{
-                                               Kind:     page.KindTaxonomy,
+                                               Kind:     kinds.KindTaxonomy,
                                                Sections: []string{"tags"},
                                                BaseName: "_index",
                                                Type:     output.HTMLFormat,
                                        }, page.TargetPaths{TargetFilename: "/tags/index.html", SubResourceBaseTarget: "/tags", Link: "/tags/"}},
                                        {
                                                "HTML page", page.TargetPathDescriptor{
-                                                       Kind:     page.KindPage,
+                                                       Kind:     kinds.KindPage,
                                                        Dir:      "/a/b",
                                                        BaseName: "mypage",
                                                        Sections: []string{"a"},
@@ -81,7 +82,7 @@ func TestPageTargetPath(t *testing.T) {
 
                                        {
                                                "HTML page with index as base", page.TargetPathDescriptor{
-                                                       Kind:     page.KindPage,
+                                                       Kind:     kinds.KindPage,
                                                        Dir:      "/a/b",
                                                        BaseName: "index",
                                                        Sections: []string{"a"},
@@ -91,7 +92,7 @@ func TestPageTargetPath(t *testing.T) {
 
                                        {
                                                "HTML page with special chars", page.TargetPathDescriptor{
-                                                       Kind:     page.KindPage,
+                                                       Kind:     kinds.KindPage,
                                                        Dir:      "/a/b",
                                                        BaseName: "My Page!",
                                                        Type:     output.HTMLFormat,
@@ -105,7 +106,7 @@ func TestPageTargetPath(t *testing.T) {
                                        }, page.TargetPaths{TargetFilename: "/sect1/index.xml", SubResourceBaseTarget: "/sect1", Link: "/sect1/index.xml"}},
                                        {
                                                "AMP page", page.TargetPathDescriptor{
-                                                       Kind:     page.KindPage,
+                                                       Kind:     kinds.KindPage,
                                                        Dir:      "/a/b/c",
                                                        BaseName: "myamp",
                                                        Type:     output.AMPFormat,
@@ -113,7 +114,7 @@ func TestPageTargetPath(t *testing.T) {
                                        },
                                        {
                                                "AMP page with URL with suffix", page.TargetPathDescriptor{
-                                                       Kind:     page.KindPage,
+                                                       Kind:     kinds.KindPage,
                                                        Dir:      "/sect/",
                                                        BaseName: "mypage",
                                                        URL:      "/some/other/url.xhtml",
@@ -122,7 +123,7 @@ func TestPageTargetPath(t *testing.T) {
                                        },
                                        {
                                                "JSON page with URL without suffix", page.TargetPathDescriptor{
-                                                       Kind:     page.KindPage,
+                                                       Kind:     kinds.KindPage,
                                                        Dir:      "/sect/",
                                                        BaseName: "mypage",
                                                        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{
-                                                       Kind:     page.KindPage,
+                                                       Kind:     kinds.KindPage,
                                                        Dir:      "/sect/",
                                                        BaseName: "mypage",
                                                        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{
-                                                       Kind:     page.KindPage,
+                                                       Kind:     kinds.KindPage,
                                                        Dir:      "/sect/",
                                                        BaseName: "mypage",
                                                        URL:      "/some/other/path",
@@ -149,7 +150,7 @@ func TestPageTargetPath(t *testing.T) {
                                        },
                                        {
                                                "HTML page with URL containing double hyphen", page.TargetPathDescriptor{
-                                                       Kind:     page.KindPage,
+                                                       Kind:     kinds.KindPage,
                                                        Dir:      "/sect/",
                                                        BaseName: "mypage",
                                                        URL:      "/some/other--url/",
@@ -158,7 +159,7 @@ func TestPageTargetPath(t *testing.T) {
                                        },
                                        {
                                                "HTML page with expanded permalink", page.TargetPathDescriptor{
-                                                       Kind:              page.KindPage,
+                                                       Kind:              kinds.KindPage,
                                                        Dir:               "/a/b",
                                                        BaseName:          "mypage",
                                                        ExpandedPermalink: "/2017/10/my-title/",
@@ -167,7 +168,7 @@ func TestPageTargetPath(t *testing.T) {
                                        },
                                        {
                                                "Paginated HTML home", page.TargetPathDescriptor{
-                                                       Kind:     page.KindHome,
+                                                       Kind:     kinds.KindHome,
                                                        BaseName: "_index",
                                                        Type:     output.HTMLFormat,
                                                        Addends:  "page/3",
@@ -175,7 +176,7 @@ func TestPageTargetPath(t *testing.T) {
                                        },
                                        {
                                                "Paginated Taxonomy terms list", page.TargetPathDescriptor{
-                                                       Kind:     page.KindTerm,
+                                                       Kind:     kinds.KindTerm,
                                                        BaseName: "_index",
                                                        Sections: []string{"tags", "hugo"},
                                                        Type:     output.HTMLFormat,
@@ -184,7 +185,7 @@ func TestPageTargetPath(t *testing.T) {
                                        },
                                        {
                                                "Regular page with addend", page.TargetPathDescriptor{
-                                                       Kind:     page.KindPage,
+                                                       Kind:     kinds.KindPage,
                                                        Dir:      "/a/b",
                                                        BaseName: "mypage",
                                                        Addends:  "c/d/e",
@@ -207,8 +208,8 @@ func TestPageTargetPath(t *testing.T) {
                                                        expected := test.expected
 
                                                        // TODO(bep) simplify
-                                                       if test.d.Kind == page.KindPage && test.d.BaseName == test.d.Type.BaseName {
-                                                       } else if test.d.Kind == page.KindHome && test.d.Type.Path != "" {
+                                                       if test.d.Kind == kinds.KindPage && test.d.BaseName == test.d.Type.BaseName {
+                                                       } 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 {
                                                                expected.TargetFilename = strings.Replace(expected.TargetFilename,
                                                                        "/"+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",
-                       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"},
                },
                {
                        "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"},
                },
        }
index 3b12e1154e07da4f6004da1d2c4563c75da46698..7fc55eccb85735de2eae78a721b18ca651f8d6ff 100644 (file)
@@ -27,6 +27,7 @@ import (
 
        "github.com/gohugoio/hugo/common/maps"
        "github.com/gohugoio/hugo/helpers"
+       "github.com/gohugoio/hugo/resources/kinds"
 )
 
 // 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
 func DecodePermalinksConfig(m map[string]any) (map[string]map[string]string, error) {
        permalinksConfig := make(map[string]map[string]string)
 
-       permalinksConfig[KindPage] = make(map[string]string)
-       permalinksConfig[KindSection] = make(map[string]string)
-       permalinksConfig[KindTaxonomy] = make(map[string]string)
-       permalinksConfig[KindTerm] = make(map[string]string)
+       permalinksConfig[kinds.KindPage] = make(map[string]string)
+       permalinksConfig[kinds.KindSection] = make(map[string]string)
+       permalinksConfig[kinds.KindTaxonomy] = make(map[string]string)
+       permalinksConfig[kinds.KindTerm] = make(map[string]string)
 
        config := maps.CleanConfigStringMap(m)
        for k, v := range config {
@@ -417,8 +418,8 @@ func DecodePermalinksConfig(m map[string]any) (map[string]map[string]string, err
                        //   key = '...'
 
                        // To sucessfully be backward compatible, "default" patterns need to be set for both page and term
-                       permalinksConfig[KindPage][k] = v
-                       permalinksConfig[KindTerm][k] = v
+                       permalinksConfig[kinds.KindPage][k] = v
+                       permalinksConfig[kinds.KindTerm][k] = v
 
                case maps.Params:
                        // [permalinks.key]