"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"
}
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
"github.com/gohugoio/hugo/helpers"
+ "github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/hugofs/files"
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}
}
"path"
"path/filepath"
"strings"
+
"sync"
"github.com/gohugoio/hugo/common/maps"
"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"
sections := s.sectionsFromFile(f)
kind := s.kindFromFileInfoOrSections(f, sections)
- if kind == page.KindTerm {
+ if kind == kinds.KindTerm {
s.PathSpec.MakePathsSanitized(sections)
}
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
parentBucket = m.s.siteBucket
}
- kind := page.KindSection
+ kind := kinds.KindSection
if s == "/" {
- kind = page.KindHome
+ kind = kinds.KindHome
}
if n.fi != nil {
}
} 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...)
"testing"
qt "github.com/frankban/quicktest"
+ "github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page"
)
return nil
}
- disableKind := page.KindPage
+ disableKind := kinds.KindPage
c.Run("Disable "+disableKind, func(c *qt.C) {
b := newSitesBuilder(c, disableKind)
b.Build(BuildCfg{})
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{})
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{})
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{})
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{})
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{})
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")
"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"
sitemapEnabled := false
for _, s := range h.Sites {
- if s.conf.IsKindEnabled(kindSitemap) {
+ if s.conf.IsKindEnabled(kinds.KindSitemap) {
sitemapEnabled = true
break
}
p, err := newPageStandalone(&pageMeta{
s: s,
- kind: kindRobotsTXT,
+ kind: kinds.KindRobotsTXT,
urlPaths: pagemeta.URLPath{
URL: "robots.txt",
},
})
allRegularPages := newLazyPagesFactory(func() page.Pages {
- return h.findPagesByKindIn(page.KindPage, allPages.get())
+ return h.findPagesByKindIn(kinds.KindPage, allPages.get())
})
for _, s := range h.Sites {
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"
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)
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")
// 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)
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")
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")
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")
// 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*")
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)
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)
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")
import (
"testing"
- "github.com/gohugoio/hugo/resources/page"
+ "github.com/gohugoio/hugo/resources/kinds"
qt "github.com/frankban/quicktest"
)
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/")
// 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")
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
// 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)
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)
"path/filepath"
"testing"
+ "github.com/gohugoio/hugo/resources/kinds"
"github.com/spf13/cast"
- "github.com/gohugoio/hugo/resources/page"
-
qt "github.com/frankban/quicktest"
)
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()
"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"
)
p.regularPagesRecursiveInit.Do(func() {
var pages page.Pages
switch p.Kind() {
- case page.KindSection:
+ case kinds.KindSection:
pages = p.getPagesRecursive()
default:
pages = p.RegularPages()
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() {
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()
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:
import (
"sync"
+ "github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page"
)
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
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
"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"
}
func (p *pageMeta) IsHome() bool {
- return p.Kind() == page.KindHome
+ return p.Kind() == kinds.KindHome
}
func (p *pageMeta) Keywords() []string {
}
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,
}
func (p *pageMeta) IsSection() bool {
- return p.Kind() == page.KindSection
+ return p.Kind() == kinds.KindSection
}
func (p *pageMeta) Section() string {
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()
} 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"
}
"sync"
"github.com/gohugoio/hugo/common/herrors"
+ "github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page"
)
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()
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugofs/files"
+ "github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page"
)
baseName = contentBaseName
}
- alwaysInSubDir := p.Kind() == kindSitemap
+ alwaysInSubDir := p.Kind() == kinds.KindSitemap
desc := page.TargetPathDescriptor{
PathSpec: d.PathSpec,
"strings"
"github.com/gohugoio/hugo/common/types"
+ "github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/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
}
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)]
-}
"github.com/gohugoio/hugo/hugofs"
+ "github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/htesting"
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))
// 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 {
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)
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
// 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.
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)
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, "")
"github.com/gohugoio/hugo/helpers"
+ "github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page"
)
})
c.regularPages = newLazyPagesFactory(func() page.Pages {
- return c.findPagesByKindIn(page.KindPage, c.pages.get())
+ return c.findPagesByKindIn(kinds.KindPage, c.pages.get())
})
return c
return 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
"time"
qt "github.com/frankban/quicktest"
+ "github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/deps"
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 {
"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"
)
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)
"github.com/gohugoio/hugo/langs"
+ "github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/config"
})
// 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] {
}
func (s *Site) isEnabled(kind string) bool {
- if kind == kindUnknown {
- panic("Unknown kind")
- }
return s.conf.IsKindEnabled(kind)
}
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...))
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(
"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"
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,
}
"strings"
"github.com/gohugoio/hugo/output"
- "github.com/gohugoio/hugo/resources/page"
+ "github.com/gohugoio/hugo/resources/kinds"
"github.com/spf13/cast"
)
}
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
seen := make(map[string]bool)
for k, v := range outputs {
- k = getKind(k)
+ k = kinds.GetKindAny(k)
if k == "" {
// Invalid kind
continue
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"
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))
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()
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()
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
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})
})
}
c := qt.New(t)
outputsConfig := map[string]any{
- page.KindHome: []string{"FOO", "JSON"},
+ kinds.KindHome: []string{"FOO", "JSON"},
}
cfg := config.New()
c := qt.New(t)
outputsConfig := map[string]any{
- page.KindHome: []string{},
+ kinds.KindHome: []string{},
}
cfg := config.New()
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()
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
"github.com/gohugoio/hugo/output"
+ "github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/resources/page/pagemeta"
)
func (s *Site) render404() error {
p, err := newPageStandalone(&pageMeta{
s: s,
- kind: kind404,
+ kind: kinds.Kind404,
urlPaths: pagemeta.URLPath{
URL: "404.html",
},
}
var d layouts.LayoutDescriptor
- d.Kind = kind404
+ d.Kind = kinds.Kind404
templ, found, err := s.Tmpl().LookupLayout(d, output.HTMLFormat)
if err != nil {
func (s *Site) renderSitemap() error {
p, err := newPageStandalone(&pageMeta{
s: s,
- kind: kindSitemap,
+ kind: kinds.KindSitemap,
urlPaths: pagemeta.URLPath{
URL: s.conf.Sitemap.Filename,
},
}
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",
},
qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/deps"
+ "github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page"
)
}},
}
- home := s.getPage(page.KindHome)
+ home := s.getPage(kinds.KindHome)
for _, test := range tests {
test := test
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 {
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
// 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/")
qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/deps"
+ "github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page"
)
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Configs: configs}, BuildCfg{SkipRender: true})
- if s.getPage(page.KindSection, "sect").Pages()[1].Title() != "Three" || s.getPage(page.KindSection, "sect").Pages()[2].Title() != "Four" {
+ if s.getPage(kinds.KindSection, "sect").Pages()[1].Title() != "Three" || s.getPage(kinds.KindSection, "sect").Pages()[2].Title() != "Four" {
t.Error("Pages in unexpected order.")
}
t.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")
}
"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"
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")
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/")
"strings"
"testing"
+ "github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page"
qt "github.com/frankban/quicktest"
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,
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")
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 {
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")
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)
--- /dev/null
+// 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
+ }
+}
--- /dev/null
+// 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)
+}
// 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)]
-}
+++ /dev/null
-// 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)
-}
"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"
)
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
"github.com/gohugoio/hugo/common/urls"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/output"
+ "github.com/gohugoio/hugo/resources/kinds"
)
const slash = "/"
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 {
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 != "" {
}
}
- } else if d.Kind == KindPage {
+ } else if d.Kind == kinds.KindPage {
if d.ExpandedPermalink != "" {
pagePath = pjoin(pagePath, d.ExpandedPermalink)
// 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)
"testing"
"github.com/gohugoio/hugo/media"
+ "github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/output"
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"},
{
"HTML page with index as base", page.TargetPathDescriptor{
- Kind: page.KindPage,
+ Kind: kinds.KindPage,
Dir: "/a/b",
BaseName: "index",
Sections: []string{"a"},
{
"HTML page with special chars", page.TargetPathDescriptor{
- Kind: page.KindPage,
+ Kind: kinds.KindPage,
Dir: "/a/b",
BaseName: "My Page!",
Type: output.HTMLFormat,
}, 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,
},
{
"AMP page with URL with suffix", page.TargetPathDescriptor{
- Kind: page.KindPage,
+ Kind: kinds.KindPage,
Dir: "/sect/",
BaseName: "mypage",
URL: "/some/other/url.xhtml",
},
{
"JSON page with URL without suffix", page.TargetPathDescriptor{
- Kind: page.KindPage,
+ Kind: kinds.KindPage,
Dir: "/sect/",
BaseName: "mypage",
URL: "/some/other/path/",
},
{
"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",
},
{
"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",
},
{
"HTML page with URL containing double hyphen", page.TargetPathDescriptor{
- Kind: page.KindPage,
+ Kind: kinds.KindPage,
Dir: "/sect/",
BaseName: "mypage",
URL: "/some/other--url/",
},
{
"HTML page with expanded permalink", page.TargetPathDescriptor{
- Kind: page.KindPage,
+ Kind: kinds.KindPage,
Dir: "/a/b",
BaseName: "mypage",
ExpandedPermalink: "/2017/10/my-title/",
},
{
"Paginated HTML home", page.TargetPathDescriptor{
- Kind: page.KindHome,
+ Kind: kinds.KindHome,
BaseName: "_index",
Type: output.HTMLFormat,
Addends: "page/3",
},
{
"Paginated Taxonomy terms list", page.TargetPathDescriptor{
- Kind: page.KindTerm,
+ Kind: kinds.KindTerm,
BaseName: "_index",
Sections: []string{"tags", "hugo"},
Type: output.HTMLFormat,
},
{
"Regular page with addend", page.TargetPathDescriptor{
- Kind: page.KindPage,
+ Kind: kinds.KindPage,
Dir: "/a/b",
BaseName: "mypage",
Addends: "c/d/e",
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,
}{
{
"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"},
},
}
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/helpers"
+ "github.com/gohugoio/hugo/resources/kinds"
)
// PermalinkExpander holds permalin mappings per section.
}
-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 {
// 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]