mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
node to page: Rename PageType to Kind
And embed that on Page. Updates #2297
This commit is contained in:
parent
96f71141bd
commit
9fba2a30a9
12 changed files with 141 additions and 138 deletions
|
@ -191,8 +191,8 @@ func (h *HugoSites) renderCrossSitesArtifacts() error {
|
||||||
|
|
||||||
func (h *HugoSites) assignMissingTranslations() error {
|
func (h *HugoSites) assignMissingTranslations() error {
|
||||||
// This looks heavy, but it should be a small number of nodes by now.
|
// This looks heavy, but it should be a small number of nodes by now.
|
||||||
allPages := h.findAllPagesByNodeTypeNotIn(PagePage)
|
allPages := h.findAllPagesByNodeTypeNotIn(KindPage)
|
||||||
for _, nodeType := range []PageType{PageHome, PageSection, PageTaxonomy, PageTaxonomyTerm} {
|
for _, nodeType := range []Kind{KindHome, KindSection, KindTaxonomy, KindTaxonomyTerm} {
|
||||||
nodes := h.findPagesByNodeTypeIn(nodeType, allPages)
|
nodes := h.findPagesByNodeTypeIn(nodeType, allPages)
|
||||||
|
|
||||||
// Assign translations
|
// Assign translations
|
||||||
|
@ -218,7 +218,7 @@ func (h *HugoSites) createMissingPages() error {
|
||||||
for _, s := range h.Sites {
|
for _, s := range h.Sites {
|
||||||
|
|
||||||
// home pages
|
// home pages
|
||||||
home := s.findPagesByNodeType(PageHome)
|
home := s.findPagesByNodeType(KindHome)
|
||||||
if len(home) > 1 {
|
if len(home) > 1 {
|
||||||
panic("Too many homes")
|
panic("Too many homes")
|
||||||
}
|
}
|
||||||
|
@ -231,8 +231,8 @@ func (h *HugoSites) createMissingPages() error {
|
||||||
// taxonomy list and terms pages
|
// taxonomy list and terms pages
|
||||||
taxonomies := s.Language.GetStringMapString("taxonomies")
|
taxonomies := s.Language.GetStringMapString("taxonomies")
|
||||||
if len(taxonomies) > 0 {
|
if len(taxonomies) > 0 {
|
||||||
taxonomyPages := s.findPagesByNodeType(PageTaxonomy)
|
taxonomyPages := s.findPagesByNodeType(KindTaxonomy)
|
||||||
taxonomyTermsPages := s.findPagesByNodeType(PageTaxonomyTerm)
|
taxonomyTermsPages := s.findPagesByNodeType(KindTaxonomyTerm)
|
||||||
for _, plural := range taxonomies {
|
for _, plural := range taxonomies {
|
||||||
tax := s.Taxonomies[plural]
|
tax := s.Taxonomies[plural]
|
||||||
foundTaxonomyPage := false
|
foundTaxonomyPage := false
|
||||||
|
@ -266,7 +266,7 @@ func (h *HugoSites) createMissingPages() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sectionPages := s.findPagesByNodeType(PageSection)
|
sectionPages := s.findPagesByNodeType(KindSection)
|
||||||
if len(sectionPages) < len(s.Sections) {
|
if len(sectionPages) < len(s.Sections) {
|
||||||
for name, section := range s.Sections {
|
for name, section := range s.Sections {
|
||||||
// A section may be created for the root content folder if a
|
// A section may be created for the root content folder if a
|
||||||
|
@ -304,9 +304,9 @@ func (h *HugoSites) createMissingPages() error {
|
||||||
|
|
||||||
// TODO(bep) np move
|
// TODO(bep) np move
|
||||||
// Move the new* methods after cleanup in site.go
|
// Move the new* methods after cleanup in site.go
|
||||||
func (s *Site) newNodePage(typ PageType) *Page {
|
func (s *Site) newNodePage(typ Kind) *Page {
|
||||||
return &Page{
|
return &Page{
|
||||||
PageType: typ,
|
Kind: typ,
|
||||||
Node: Node{
|
Node: Node{
|
||||||
Data: make(map[string]interface{}),
|
Data: make(map[string]interface{}),
|
||||||
Site: &s.Info,
|
Site: &s.Info,
|
||||||
|
@ -315,7 +315,7 @@ func (s *Site) newNodePage(typ PageType) *Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) newHomePage() *Page {
|
func (s *Site) newHomePage() *Page {
|
||||||
p := s.newNodePage(PageHome)
|
p := s.newNodePage(KindHome)
|
||||||
p.Title = s.Info.Title
|
p.Title = s.Info.Title
|
||||||
pages := Pages{}
|
pages := Pages{}
|
||||||
p.Data["Pages"] = pages
|
p.Data["Pages"] = pages
|
||||||
|
@ -334,7 +334,7 @@ func (s *Site) setPageURLs(p *Page, in string) {
|
||||||
|
|
||||||
func (s *Site) newTaxonomyPage(plural, key string) *Page {
|
func (s *Site) newTaxonomyPage(plural, key string) *Page {
|
||||||
|
|
||||||
p := s.newNodePage(PageTaxonomy)
|
p := s.newNodePage(KindTaxonomy)
|
||||||
|
|
||||||
p.sections = []string{plural, key}
|
p.sections = []string{plural, key}
|
||||||
|
|
||||||
|
@ -356,7 +356,7 @@ func (s *Site) newTaxonomyPage(plural, key string) *Page {
|
||||||
|
|
||||||
func (s *Site) newSectionPage(name string, section WeightedPages) *Page {
|
func (s *Site) newSectionPage(name string, section WeightedPages) *Page {
|
||||||
|
|
||||||
p := s.newNodePage(PageSection)
|
p := s.newNodePage(KindSection)
|
||||||
p.sections = []string{name}
|
p.sections = []string{name}
|
||||||
|
|
||||||
sectionName := name
|
sectionName := name
|
||||||
|
@ -375,7 +375,7 @@ func (s *Site) newSectionPage(name string, section WeightedPages) *Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) newTaxonomyTermsPage(plural string) *Page {
|
func (s *Site) newTaxonomyTermsPage(plural string) *Page {
|
||||||
p := s.newNodePage(PageTaxonomyTerm)
|
p := s.newNodePage(KindTaxonomyTerm)
|
||||||
p.sections = []string{plural}
|
p.sections = []string{plural}
|
||||||
p.Title = strings.Title(plural)
|
p.Title = strings.Title(plural)
|
||||||
s.setPageURLs(p, plural)
|
s.setPageURLs(p, plural)
|
||||||
|
@ -566,19 +566,19 @@ func (s *Site) updateBuildStats(page *Page) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(bep) np remove
|
// TODO(bep) np remove
|
||||||
func (h *HugoSites) findAllPagesByNodeType(n PageType) Pages {
|
func (h *HugoSites) findAllPagesByNodeType(n Kind) Pages {
|
||||||
return h.Sites[0].findAllPagesByNodeType(n)
|
return h.Sites[0].findAllPagesByNodeType(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HugoSites) findPagesByNodeTypeNotIn(n PageType, inPages Pages) Pages {
|
func (h *HugoSites) findPagesByNodeTypeNotIn(n Kind, inPages Pages) Pages {
|
||||||
return h.Sites[0].findPagesByNodeTypeNotIn(n, inPages)
|
return h.Sites[0].findPagesByNodeTypeNotIn(n, inPages)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HugoSites) findPagesByNodeTypeIn(n PageType, inPages Pages) Pages {
|
func (h *HugoSites) findPagesByNodeTypeIn(n Kind, inPages Pages) Pages {
|
||||||
return h.Sites[0].findPagesByNodeTypeIn(n, inPages)
|
return h.Sites[0].findPagesByNodeTypeIn(n, inPages)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HugoSites) findAllPagesByNodeTypeNotIn(n PageType) Pages {
|
func (h *HugoSites) findAllPagesByNodeTypeNotIn(n Kind) Pages {
|
||||||
return h.findPagesByNodeTypeNotIn(n, h.Sites[0].AllPages)
|
return h.findPagesByNodeTypeNotIn(n, h.Sites[0].AllPages)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -296,7 +296,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
|
||||||
assertFileContent(t, "public/en/sect/doc1-slug/index.html", true, "Single", "Shortcode: Hello")
|
assertFileContent(t, "public/en/sect/doc1-slug/index.html", true, "Single", "Shortcode: Hello")
|
||||||
|
|
||||||
// Check node translations
|
// Check node translations
|
||||||
homeEn := enSite.getPage(PageHome)
|
homeEn := enSite.getPage(KindHome)
|
||||||
require.NotNil(t, homeEn)
|
require.NotNil(t, homeEn)
|
||||||
require.Len(t, homeEn.Translations(), 3)
|
require.Len(t, homeEn.Translations(), 3)
|
||||||
require.Equal(t, "fr", homeEn.Translations()[0].Lang())
|
require.Equal(t, "fr", homeEn.Translations()[0].Lang())
|
||||||
|
@ -306,7 +306,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
|
||||||
require.Equal(t, "På bokmål", homeEn.Translations()[2].Title, configSuffix)
|
require.Equal(t, "På bokmål", homeEn.Translations()[2].Title, configSuffix)
|
||||||
require.Equal(t, "Bokmål", homeEn.Translations()[2].Language().LanguageName, configSuffix)
|
require.Equal(t, "Bokmål", homeEn.Translations()[2].Language().LanguageName, configSuffix)
|
||||||
|
|
||||||
sectFr := frSite.getPage(PageSection, "sect")
|
sectFr := frSite.getPage(KindSection, "sect")
|
||||||
require.NotNil(t, sectFr)
|
require.NotNil(t, sectFr)
|
||||||
|
|
||||||
require.Equal(t, "fr", sectFr.Lang())
|
require.Equal(t, "fr", sectFr.Lang())
|
||||||
|
@ -316,12 +316,12 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
|
||||||
|
|
||||||
nnSite := sites.Sites[2]
|
nnSite := sites.Sites[2]
|
||||||
require.Equal(t, "nn", nnSite.Language.Lang)
|
require.Equal(t, "nn", nnSite.Language.Lang)
|
||||||
taxNn := nnSite.getPage(PageTaxonomyTerm, "lag")
|
taxNn := nnSite.getPage(KindTaxonomyTerm, "lag")
|
||||||
require.NotNil(t, taxNn)
|
require.NotNil(t, taxNn)
|
||||||
require.Len(t, taxNn.Translations(), 1)
|
require.Len(t, taxNn.Translations(), 1)
|
||||||
require.Equal(t, "nb", taxNn.Translations()[0].Lang())
|
require.Equal(t, "nb", taxNn.Translations()[0].Lang())
|
||||||
|
|
||||||
taxTermNn := nnSite.getPage(PageTaxonomy, "lag", "sogndal")
|
taxTermNn := nnSite.getPage(KindTaxonomy, "lag", "sogndal")
|
||||||
require.NotNil(t, taxTermNn)
|
require.NotNil(t, taxTermNn)
|
||||||
require.Len(t, taxTermNn.Translations(), 1)
|
require.Len(t, taxTermNn.Translations(), 1)
|
||||||
require.Equal(t, "nb", taxTermNn.Translations()[0].Lang())
|
require.Equal(t, "nb", taxTermNn.Translations()[0].Lang())
|
||||||
|
@ -514,7 +514,7 @@ func TestMultiSitesRebuild(t *testing.T) {
|
||||||
docFr := readDestination(t, "public/fr/sect/doc1/index.html")
|
docFr := readDestination(t, "public/fr/sect/doc1/index.html")
|
||||||
require.True(t, strings.Contains(docFr, "Salut"), "No Salut")
|
require.True(t, strings.Contains(docFr, "Salut"), "No Salut")
|
||||||
|
|
||||||
homeEn := enSite.getPage(PageHome)
|
homeEn := enSite.getPage(KindHome)
|
||||||
require.NotNil(t, homeEn)
|
require.NotNil(t, homeEn)
|
||||||
require.Len(t, homeEn.Translations(), 3)
|
require.Len(t, homeEn.Translations(), 3)
|
||||||
require.Equal(t, "fr", homeEn.Translations()[0].Lang())
|
require.Equal(t, "fr", homeEn.Translations()[0].Lang())
|
||||||
|
@ -621,7 +621,7 @@ title = "Svenska"
|
||||||
require.True(t, svSite.Language.Lang == "sv", svSite.Language.Lang)
|
require.True(t, svSite.Language.Lang == "sv", svSite.Language.Lang)
|
||||||
require.True(t, frSite.Language.Lang == "fr", frSite.Language.Lang)
|
require.True(t, frSite.Language.Lang == "fr", frSite.Language.Lang)
|
||||||
|
|
||||||
homeEn := enSite.getPage(PageHome)
|
homeEn := enSite.getPage(KindHome)
|
||||||
require.NotNil(t, homeEn)
|
require.NotNil(t, homeEn)
|
||||||
require.Len(t, homeEn.Translations(), 4)
|
require.Len(t, homeEn.Translations(), 4)
|
||||||
require.Equal(t, "sv", homeEn.Translations()[0].Lang())
|
require.Equal(t, "sv", homeEn.Translations()[0].Lang())
|
||||||
|
|
|
@ -415,11 +415,11 @@ func doTestSectionPagesMenu(canonifyURLs bool, t *testing.T) {
|
||||||
fishySectionPages := s.Sections["fish-and-chips"]
|
fishySectionPages := s.Sections["fish-and-chips"]
|
||||||
assert.Equal(t, 1, len(fishySectionPages))
|
assert.Equal(t, 1, len(fishySectionPages))
|
||||||
|
|
||||||
nodeFirst := s.getPage(PageSection, "first")
|
nodeFirst := s.getPage(KindSection, "first")
|
||||||
require.NotNil(t, nodeFirst)
|
require.NotNil(t, nodeFirst)
|
||||||
nodeSecond := s.getPage(PageSection, "second-section")
|
nodeSecond := s.getPage(KindSection, "second-section")
|
||||||
require.NotNil(t, nodeSecond)
|
require.NotNil(t, nodeSecond)
|
||||||
nodeFishy := s.getPage(PageSection, "fish-and-chips")
|
nodeFishy := s.getPage(KindSection, "fish-and-chips")
|
||||||
require.Equal(t, "fish-and-chips", nodeFishy.sections[0])
|
require.Equal(t, "fish-and-chips", nodeFishy.sections[0])
|
||||||
|
|
||||||
firstSectionMenuEntry := findTestMenuEntryByID(s, "spm", "first")
|
firstSectionMenuEntry := findTestMenuEntryByID(s, "spm", "first")
|
||||||
|
@ -555,7 +555,7 @@ func TestHomeNodeMenu(t *testing.T) {
|
||||||
|
|
||||||
s := setupMenuTests(t, menuPageSources)
|
s := setupMenuTests(t, menuPageSources)
|
||||||
|
|
||||||
home := s.getPage(PageHome)
|
home := s.getPage(KindHome)
|
||||||
|
|
||||||
homeMenuEntry := &MenuEntry{Name: home.Title, URL: home.URL()}
|
homeMenuEntry := &MenuEntry{Name: home.Title, URL: home.URL()}
|
||||||
|
|
||||||
|
|
|
@ -176,7 +176,7 @@ func (n *Node) Lang() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) isTranslation(candidate *Page) bool {
|
func (p *Page) isTranslation(candidate *Page) bool {
|
||||||
if p == candidate || p.PageType != candidate.PageType {
|
if p == candidate || p.Kind != candidate.Kind {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ func (p *Page) isTranslation(candidate *Page) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.PageType == PagePage || p.PageType == pageUnknown {
|
if p.Kind == KindPage || p.Kind == kindUnknown {
|
||||||
panic("Node type not currently supported for this op")
|
panic("Node type not currently supported for this op")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,41 +291,41 @@ func sectionsFromFilename(filename string) []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(bep) np node identificator
|
// TODO(bep) np node identificator
|
||||||
func nodeTypeFromFilename(filename string) PageType {
|
func nodeTypeFromFilename(filename string) Kind {
|
||||||
if !strings.Contains(filename, "_index") {
|
if !strings.Contains(filename, "_index") {
|
||||||
return PagePage
|
return KindPage
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(filename, "_index") {
|
if strings.HasPrefix(filename, "_index") {
|
||||||
return PageHome
|
return KindHome
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't know enough yet to determine the type.
|
// We don't know enough yet to determine the type.
|
||||||
return pageUnknown
|
return kindUnknown
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) setNodeTypeVars(s *Site) {
|
func (p *Page) setNodeTypeVars(s *Site) {
|
||||||
// TODO(bep) np taxonomies etc.
|
// TODO(bep) np taxonomies etc.
|
||||||
if p.PageType == pageUnknown {
|
if p.Kind == kindUnknown {
|
||||||
// This is either a taxonomy list, taxonomy term or a section
|
// This is either a taxonomy list, taxonomy term or a section
|
||||||
nodeType := s.nodeTypeFromSections(p.sections)
|
nodeType := s.nodeTypeFromSections(p.sections)
|
||||||
|
|
||||||
if nodeType == pageUnknown {
|
if nodeType == kindUnknown {
|
||||||
panic(fmt.Sprintf("Unable to determine node type from %q", p.sections))
|
panic(fmt.Sprintf("Unable to determine node type from %q", p.sections))
|
||||||
}
|
}
|
||||||
|
|
||||||
p.PageType = nodeType
|
p.Kind = nodeType
|
||||||
}
|
}
|
||||||
// TODO(bep) np node URL
|
// TODO(bep) np node URL
|
||||||
// Set Node URL
|
// Set Node URL
|
||||||
switch p.PageType {
|
switch p.Kind {
|
||||||
case PageHome:
|
case KindHome:
|
||||||
p.URLPath.URL = ""
|
p.URLPath.URL = ""
|
||||||
case PageSection:
|
case KindSection:
|
||||||
p.URLPath.URL = p.sections[0]
|
p.URLPath.URL = p.sections[0]
|
||||||
case PageTaxonomy:
|
case KindTaxonomy:
|
||||||
p.URLPath.URL = path.Join(p.sections...)
|
p.URLPath.URL = path.Join(p.sections...)
|
||||||
case PageTaxonomyTerm:
|
case KindTaxonomyTerm:
|
||||||
p.URLPath.URL = path.Join(p.sections...)
|
p.URLPath.URL = path.Join(p.sections...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ func TestNodesAsPage(t *testing.T) {
|
||||||
assertFileContent(t, filepath.Join("public", "sect1", "regular1", "index.html"), false, "Single Title: Page 01", "Content Page 01")
|
assertFileContent(t, filepath.Join("public", "sect1", "regular1", "index.html"), false, "Single Title: Page 01", "Content Page 01")
|
||||||
|
|
||||||
h := s.owner
|
h := s.owner
|
||||||
nodes := h.findAllPagesByNodeTypeNotIn(PagePage)
|
nodes := h.findAllPagesByNodeTypeNotIn(KindPage)
|
||||||
require.Len(t, nodes, 6)
|
require.Len(t, nodes, 6)
|
||||||
|
|
||||||
home := nodes[5] // oldest
|
home := nodes[5] // oldest
|
||||||
|
@ -88,7 +88,7 @@ func TestNodesAsPage(t *testing.T) {
|
||||||
section2 := nodes[3]
|
section2 := nodes[3]
|
||||||
require.Equal(t, "Section2", section2.Title)
|
require.Equal(t, "Section2", section2.Title)
|
||||||
|
|
||||||
pages := h.findAllPagesByNodeType(PagePage)
|
pages := h.findAllPagesByNodeType(KindPage)
|
||||||
require.Len(t, pages, 4)
|
require.Len(t, pages, 4)
|
||||||
|
|
||||||
first := pages[0]
|
first := pages[0]
|
||||||
|
@ -118,7 +118,7 @@ func TestNodesAsPage(t *testing.T) {
|
||||||
assertFileContent(t, filepath.Join("public", "sect1", "page", "2", "index.html"), false,
|
assertFileContent(t, filepath.Join("public", "sect1", "page", "2", "index.html"), false,
|
||||||
"Pag: Page 02")
|
"Pag: Page 02")
|
||||||
|
|
||||||
sections := h.findAllPagesByNodeType(PageSection)
|
sections := h.findAllPagesByNodeType(KindSection)
|
||||||
|
|
||||||
require.Len(t, sections, 2)
|
require.Len(t, sections, 2)
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ func TestNodesWithNoContentFile(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Home page
|
// Home page
|
||||||
homePages := s.findIndexNodesByNodeType(PageHome)
|
homePages := s.findIndexNodesByNodeType(KindHome)
|
||||||
require.Len(t, homePages, 1)
|
require.Len(t, homePages, 1)
|
||||||
|
|
||||||
homePage := homePages[0]
|
homePage := homePages[0]
|
||||||
|
|
115
hugolib/page.go
115
hugolib/page.go
|
@ -49,38 +49,53 @@ var (
|
||||||
cjk = regexp.MustCompile(`\p{Han}|\p{Hangul}|\p{Hiragana}|\p{Katakana}`)
|
cjk = regexp.MustCompile(`\p{Han}|\p{Hangul}|\p{Hiragana}|\p{Katakana}`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// PageType is the discriminator that identifies the different page types
|
// Kind is the discriminator that identifies the different page types
|
||||||
// in the different page collections. This can, as an example, be used
|
// in the different page collections. This can, as an example, be used
|
||||||
// to to filter regular pages, find sections etc.
|
// to to filter regular pages, find sections etc.
|
||||||
// NOTE: THe exported constants below are used to filter pages from
|
// NOTE: THe exported constants below are used to filter pages from
|
||||||
// templates in the wild, so do not change the values!
|
// templates in the wild, so do not change the values!
|
||||||
type PageType string
|
type Kind string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PagePage PageType = "page"
|
KindPage Kind = "page"
|
||||||
|
|
||||||
// The rest are node types; home page, sections etc.
|
// The rest are node types; home page, sections etc.
|
||||||
PageHome PageType = "home"
|
KindHome Kind = "home"
|
||||||
PageSection PageType = "section"
|
KindSection Kind = "section"
|
||||||
PageTaxonomy PageType = "taxonomy"
|
KindTaxonomy Kind = "taxonomy"
|
||||||
PageTaxonomyTerm PageType = "taxonomyTerm"
|
KindTaxonomyTerm Kind = "taxonomyTerm"
|
||||||
|
|
||||||
// Temporary state.
|
// Temporary state.
|
||||||
pageUnknown PageType = "unknown"
|
kindUnknown Kind = "unknown"
|
||||||
|
|
||||||
// The following are (currently) temporary nodes,
|
// The following are (currently) temporary nodes,
|
||||||
// i.e. nodes we create just to render in isolation.
|
// i.e. nodes we create just to render in isolation.
|
||||||
pageSitemap PageType = "sitemap"
|
kindSitemap Kind = "sitemap"
|
||||||
pageRobotsTXT PageType = "robotsTXT"
|
kindRobotsTXT Kind = "robotsTXT"
|
||||||
page404 PageType = "404"
|
kind404 Kind = "404"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p PageType) IsNode() bool {
|
// IsNode returns whether this is an item of one of the list types in Hugo,
|
||||||
return p != PagePage
|
// i.e. not a regular content page.
|
||||||
|
func (k Kind) IsNode() bool {
|
||||||
|
return k != KindPage
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsHome returns whether this is the home page.
|
||||||
|
func (k Kind) IsHome() bool {
|
||||||
|
return k == KindHome
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsPage returns whether this is a regular content page.
|
||||||
|
func (k Kind) IsPage() bool {
|
||||||
|
return k == KindPage
|
||||||
}
|
}
|
||||||
|
|
||||||
type Page struct {
|
type Page struct {
|
||||||
PageType PageType
|
|
||||||
|
// Kind will, for the pages available to the templates, be one of:
|
||||||
|
// page, home, section, taxonomy and taxonomyTerm.
|
||||||
|
Kind
|
||||||
|
|
||||||
// Since Hugo 0.18 we got rid of the Node type. So now all pages are ...
|
// Since Hugo 0.18 we got rid of the Node type. So now all pages are ...
|
||||||
// pages (regular pages, home page, sections etc.).
|
// pages (regular pages, home page, sections etc.).
|
||||||
|
@ -185,18 +200,6 @@ func (*PageMeta) ReadingTime() int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) IsNode() bool {
|
|
||||||
return p.PageType.IsNode()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Page) IsHome() bool {
|
|
||||||
return p.PageType == PageHome
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Page) IsPage() bool {
|
|
||||||
return p.PageType == PagePage
|
|
||||||
}
|
|
||||||
|
|
||||||
type Position struct {
|
type Position struct {
|
||||||
Prev *Page
|
Prev *Page
|
||||||
Next *Page
|
Next *Page
|
||||||
|
@ -482,7 +485,7 @@ func (p *Page) getRenderingConfig() *helpers.Blackfriday {
|
||||||
|
|
||||||
func newPage(filename string) *Page {
|
func newPage(filename string) *Page {
|
||||||
page := Page{
|
page := Page{
|
||||||
PageType: nodeTypeFromFilename(filename),
|
Kind: nodeTypeFromFilename(filename),
|
||||||
contentType: "",
|
contentType: "",
|
||||||
Source: Source{File: *source.NewFile(filename)},
|
Source: Source{File: *source.NewFile(filename)},
|
||||||
Node: Node{Keywords: []string{}, Sitemap: Sitemap{Priority: -1}},
|
Node: Node{Keywords: []string{}, Sitemap: Sitemap{Priority: -1}},
|
||||||
|
@ -521,16 +524,16 @@ func (p *Page) layouts(l ...string) []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(bep) np taxonomy etc.
|
// TODO(bep) np taxonomy etc.
|
||||||
switch p.PageType {
|
switch p.Kind {
|
||||||
case PageHome:
|
case KindHome:
|
||||||
return []string{"index.html", "_default/list.html"}
|
return []string{"index.html", "_default/list.html"}
|
||||||
case PageSection:
|
case KindSection:
|
||||||
section := p.sections[0]
|
section := p.sections[0]
|
||||||
return []string{"section/" + section + ".html", "_default/section.html", "_default/list.html", "indexes/" + section + ".html", "_default/indexes.html"}
|
return []string{"section/" + section + ".html", "_default/section.html", "_default/list.html", "indexes/" + section + ".html", "_default/indexes.html"}
|
||||||
case PageTaxonomy:
|
case KindTaxonomy:
|
||||||
singular := p.site.taxonomiesPluralSingular[p.sections[0]]
|
singular := p.site.taxonomiesPluralSingular[p.sections[0]]
|
||||||
return []string{"taxonomy/" + singular + ".html", "indexes/" + singular + ".html", "_default/taxonomy.html", "_default/list.html"}
|
return []string{"taxonomy/" + singular + ".html", "indexes/" + singular + ".html", "_default/taxonomy.html", "_default/list.html"}
|
||||||
case PageTaxonomyTerm:
|
case KindTaxonomyTerm:
|
||||||
singular := p.site.taxonomiesPluralSingular[p.sections[0]]
|
singular := p.site.taxonomiesPluralSingular[p.sections[0]]
|
||||||
return []string{"taxonomy/" + singular + ".terms.html", "_default/terms.html", "indexes/indexes.html"}
|
return []string{"taxonomy/" + singular + ".terms.html", "_default/terms.html", "indexes/indexes.html"}
|
||||||
}
|
}
|
||||||
|
@ -555,18 +558,18 @@ func (p *Page) layouts(l ...string) []string {
|
||||||
// rssLayouts returns RSS layouts to use for the RSS version of this page, nil
|
// rssLayouts returns RSS layouts to use for the RSS version of this page, nil
|
||||||
// if no RSS should be rendered.
|
// if no RSS should be rendered.
|
||||||
func (p *Page) rssLayouts() []string {
|
func (p *Page) rssLayouts() []string {
|
||||||
switch p.PageType {
|
switch p.Kind {
|
||||||
case PageHome:
|
case KindHome:
|
||||||
return []string{"rss.xml", "_default/rss.xml", "_internal/_default/rss.xml"}
|
return []string{"rss.xml", "_default/rss.xml", "_internal/_default/rss.xml"}
|
||||||
case PageSection:
|
case KindSection:
|
||||||
section := p.sections[0]
|
section := p.sections[0]
|
||||||
return []string{"section/" + section + ".rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"}
|
return []string{"section/" + section + ".rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"}
|
||||||
case PageTaxonomy:
|
case KindTaxonomy:
|
||||||
singular := p.site.taxonomiesPluralSingular[p.sections[0]]
|
singular := p.site.taxonomiesPluralSingular[p.sections[0]]
|
||||||
return []string{"taxonomy/" + singular + ".rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"}
|
return []string{"taxonomy/" + singular + ".rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"}
|
||||||
case PageTaxonomyTerm:
|
case KindTaxonomyTerm:
|
||||||
// No RSS for taxonomy terms
|
// No RSS for taxonomy terms
|
||||||
case PagePage:
|
case KindPage:
|
||||||
// No RSS for regular pages
|
// No RSS for regular pages
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -776,7 +779,7 @@ func (p *Page) IsExpired() bool {
|
||||||
|
|
||||||
func (p *Page) Permalink() (string, error) {
|
func (p *Page) Permalink() (string, error) {
|
||||||
// TODO(bep) np permalink
|
// TODO(bep) np permalink
|
||||||
if p.PageType.IsNode() {
|
if p.IsNode() {
|
||||||
return p.Node.Permalink(), nil
|
return p.Node.Permalink(), nil
|
||||||
}
|
}
|
||||||
link, err := p.permalink()
|
link, err := p.permalink()
|
||||||
|
@ -1014,7 +1017,7 @@ func (p *Page) getParam(key string, stringToLower bool) interface{} {
|
||||||
|
|
||||||
func (p *Page) HasMenuCurrent(menu string, me *MenuEntry) bool {
|
func (p *Page) HasMenuCurrent(menu string, me *MenuEntry) bool {
|
||||||
// TODO(bep) np menu
|
// TODO(bep) np menu
|
||||||
if p.PageType.IsNode() {
|
if p.IsNode() {
|
||||||
return p.Node.HasMenuCurrent(menu, me)
|
return p.Node.HasMenuCurrent(menu, me)
|
||||||
}
|
}
|
||||||
menus := p.Menus()
|
menus := p.Menus()
|
||||||
|
@ -1044,7 +1047,7 @@ func (p *Page) HasMenuCurrent(menu string, me *MenuEntry) bool {
|
||||||
|
|
||||||
func (p *Page) IsMenuCurrent(menu string, inme *MenuEntry) bool {
|
func (p *Page) IsMenuCurrent(menu string, inme *MenuEntry) bool {
|
||||||
// TODO(bep) np menu
|
// TODO(bep) np menu
|
||||||
if p.PageType.IsNode() {
|
if p.IsNode() {
|
||||||
return p.Node.IsMenuCurrent(menu, inme)
|
return p.Node.IsMenuCurrent(menu, inme)
|
||||||
}
|
}
|
||||||
menus := p.Menus()
|
menus := p.Menus()
|
||||||
|
@ -1253,14 +1256,14 @@ func (p *Page) FullFilePath() string {
|
||||||
func (p *Page) TargetPath() (outfile string) {
|
func (p *Page) TargetPath() (outfile string) {
|
||||||
|
|
||||||
// TODO(bep) np
|
// TODO(bep) np
|
||||||
switch p.PageType {
|
switch p.Kind {
|
||||||
case PageHome:
|
case KindHome:
|
||||||
return p.addLangFilepathPrefix(helpers.FilePathSeparator)
|
return p.addLangFilepathPrefix(helpers.FilePathSeparator)
|
||||||
case PageSection:
|
case KindSection:
|
||||||
return p.addLangFilepathPrefix(p.sections[0])
|
return p.addLangFilepathPrefix(p.sections[0])
|
||||||
case PageTaxonomy:
|
case KindTaxonomy:
|
||||||
return p.addLangFilepathPrefix(filepath.Join(p.sections...))
|
return p.addLangFilepathPrefix(filepath.Join(p.sections...))
|
||||||
case PageTaxonomyTerm:
|
case KindTaxonomyTerm:
|
||||||
return p.addLangFilepathPrefix(filepath.Join(p.sections...))
|
return p.addLangFilepathPrefix(filepath.Join(p.sections...))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1305,7 +1308,7 @@ func (p *Page) TargetPath() (outfile string) {
|
||||||
|
|
||||||
func (p *Page) prepareLayouts() error {
|
func (p *Page) prepareLayouts() error {
|
||||||
// TODO(bep): Check the IsRenderable logic.
|
// TODO(bep): Check the IsRenderable logic.
|
||||||
if p.PageType == PagePage {
|
if p.Kind == KindPage {
|
||||||
var layouts []string
|
var layouts []string
|
||||||
if !p.IsRenderable() {
|
if !p.IsRenderable() {
|
||||||
self := "__" + p.TargetPath()
|
self := "__" + p.TargetPath()
|
||||||
|
@ -1329,17 +1332,17 @@ func (p *Page) prepareData(s *Site) error {
|
||||||
var pages Pages
|
var pages Pages
|
||||||
|
|
||||||
p.Data = make(map[string]interface{})
|
p.Data = make(map[string]interface{})
|
||||||
switch p.PageType {
|
switch p.Kind {
|
||||||
case PagePage:
|
case KindPage:
|
||||||
case PageHome:
|
case KindHome:
|
||||||
pages = s.findPagesByNodeTypeNotIn(PageHome, s.Pages)
|
pages = s.findPagesByNodeTypeNotIn(KindHome, s.Pages)
|
||||||
case PageSection:
|
case KindSection:
|
||||||
sectionData, ok := s.Sections[p.sections[0]]
|
sectionData, ok := s.Sections[p.sections[0]]
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("Data for section %s not found", p.Section())
|
return fmt.Errorf("Data for section %s not found", p.Section())
|
||||||
}
|
}
|
||||||
pages = sectionData.Pages()
|
pages = sectionData.Pages()
|
||||||
case PageTaxonomy:
|
case KindTaxonomy:
|
||||||
plural := p.sections[0]
|
plural := p.sections[0]
|
||||||
term := p.sections[1]
|
term := p.sections[1]
|
||||||
|
|
||||||
|
@ -1350,7 +1353,7 @@ func (p *Page) prepareData(s *Site) error {
|
||||||
p.Data["Singular"] = singular
|
p.Data["Singular"] = singular
|
||||||
p.Data["Plural"] = plural
|
p.Data["Plural"] = plural
|
||||||
pages = taxonomy.Pages()
|
pages = taxonomy.Pages()
|
||||||
case PageTaxonomyTerm:
|
case KindTaxonomyTerm:
|
||||||
plural := p.sections[0]
|
plural := p.sections[0]
|
||||||
singular := s.taxonomiesPluralSingular[plural]
|
singular := s.taxonomiesPluralSingular[plural]
|
||||||
|
|
||||||
|
@ -1375,7 +1378,7 @@ func (p *Page) updatePageDates() {
|
||||||
// TODO(bep) np there is a potential issue with page sorting for home pages
|
// TODO(bep) np there is a potential issue with page sorting for home pages
|
||||||
// etc. without front matter dates set, but let us wrap the head around
|
// etc. without front matter dates set, but let us wrap the head around
|
||||||
// that in another time.
|
// that in another time.
|
||||||
if !p.PageType.IsNode() {
|
if !p.Kind.IsNode() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1415,7 +1418,7 @@ func (p *Page) updatePageDates() {
|
||||||
// the paginators etc., we do it manually here.
|
// the paginators etc., we do it manually here.
|
||||||
// TODO(bep) np do better
|
// TODO(bep) np do better
|
||||||
func (p *Page) copy() *Page {
|
func (p *Page) copy() *Page {
|
||||||
c := &Page{PageType: p.PageType, Node: Node{Site: p.Site}}
|
c := &Page{Kind: p.Kind, Node: Node{Site: p.Site}}
|
||||||
c.Title = p.Title
|
c.Title = p.Title
|
||||||
c.Data = p.Data
|
c.Data = p.Data
|
||||||
c.Date = p.Date
|
c.Date = p.Date
|
||||||
|
|
|
@ -40,12 +40,12 @@ type PageCollections struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *PageCollections) refreshPageCaches() {
|
func (c *PageCollections) refreshPageCaches() {
|
||||||
c.indexPages = c.findPagesByNodeTypeNotIn(PagePage, c.Pages)
|
c.indexPages = c.findPagesByNodeTypeNotIn(KindPage, c.Pages)
|
||||||
c.regularPages = c.findPagesByNodeTypeIn(PagePage, c.Pages)
|
c.regularPages = c.findPagesByNodeTypeIn(KindPage, c.Pages)
|
||||||
|
|
||||||
// TODO(bep) np remove eventually
|
// TODO(bep) np remove eventually
|
||||||
for _, n := range c.Pages {
|
for _, n := range c.Pages {
|
||||||
if n.PageType == pageUnknown {
|
if n.Kind == kindUnknown {
|
||||||
panic(fmt.Sprintf("Got unknown type %s", n.Title))
|
panic(fmt.Sprintf("Got unknown type %s", n.Title))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,11 +61,11 @@ func newPageCollectionsFromPages(pages Pages) *PageCollections {
|
||||||
|
|
||||||
// TODO(bep) np clean and remove finders
|
// TODO(bep) np clean and remove finders
|
||||||
|
|
||||||
func (c *PageCollections) findPagesByNodeType(n PageType) Pages {
|
func (c *PageCollections) findPagesByNodeType(n Kind) Pages {
|
||||||
return c.findPagesByNodeTypeIn(n, c.Pages)
|
return c.findPagesByNodeTypeIn(n, c.Pages)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *PageCollections) getPage(typ PageType, path ...string) *Page {
|
func (c *PageCollections) getPage(typ Kind, path ...string) *Page {
|
||||||
pages := c.findPagesByNodeTypeIn(typ, c.Pages)
|
pages := c.findPagesByNodeTypeIn(typ, c.Pages)
|
||||||
|
|
||||||
if len(pages) == 0 {
|
if len(pages) == 0 {
|
||||||
|
@ -94,35 +94,35 @@ func (c *PageCollections) getPage(typ PageType, path ...string) *Page {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *PageCollections) findIndexNodesByNodeType(n PageType) Pages {
|
func (c *PageCollections) findIndexNodesByNodeType(n Kind) Pages {
|
||||||
return c.findPagesByNodeTypeIn(n, c.indexPages)
|
return c.findPagesByNodeTypeIn(n, c.indexPages)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*PageCollections) findPagesByNodeTypeIn(n PageType, inPages Pages) Pages {
|
func (*PageCollections) findPagesByNodeTypeIn(n Kind, inPages Pages) Pages {
|
||||||
var pages Pages
|
var pages Pages
|
||||||
for _, p := range inPages {
|
for _, p := range inPages {
|
||||||
if p.PageType == n {
|
if p.Kind == n {
|
||||||
pages = append(pages, p)
|
pages = append(pages, p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pages
|
return pages
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*PageCollections) findPagesByNodeTypeNotIn(n PageType, inPages Pages) Pages {
|
func (*PageCollections) findPagesByNodeTypeNotIn(n Kind, inPages Pages) Pages {
|
||||||
var pages Pages
|
var pages Pages
|
||||||
for _, p := range inPages {
|
for _, p := range inPages {
|
||||||
if p.PageType != n {
|
if p.Kind != n {
|
||||||
pages = append(pages, p)
|
pages = append(pages, p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pages
|
return pages
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *PageCollections) findAllPagesByNodeType(n PageType) Pages {
|
func (c *PageCollections) findAllPagesByNodeType(n Kind) Pages {
|
||||||
return c.findPagesByNodeTypeIn(n, c.Pages)
|
return c.findPagesByNodeTypeIn(n, c.Pages)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *PageCollections) findRawAllPagesByNodeType(n PageType) Pages {
|
func (c *PageCollections) findRawAllPagesByNodeType(n Kind) Pages {
|
||||||
return c.findPagesByNodeTypeIn(n, c.rawAllPages)
|
return c.findPagesByNodeTypeIn(n, c.rawAllPages)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ func TestPermalink(t *testing.T) {
|
||||||
info := newSiteInfo(siteBuilderCfg{baseURL: string(test.base), language: helpers.NewDefaultLanguage()})
|
info := newSiteInfo(siteBuilderCfg{baseURL: string(test.base), language: helpers.NewDefaultLanguage()})
|
||||||
|
|
||||||
p := &Page{
|
p := &Page{
|
||||||
PageType: PagePage,
|
Kind: KindPage,
|
||||||
Node: Node{
|
Node: Node{
|
||||||
URLPath: URLPath{
|
URLPath: URLPath{
|
||||||
Section: "z",
|
Section: "z",
|
||||||
|
|
|
@ -1269,7 +1269,7 @@ func TestIndexPageSimpleMethods(t *testing.T) {
|
||||||
{func(n *Page) bool { return n.Now().Unix() == time.Now().Unix() }},
|
{func(n *Page) bool { return n.Now().Unix() == time.Now().Unix() }},
|
||||||
} {
|
} {
|
||||||
|
|
||||||
n := &Page{PageType: PageHome}
|
n := &Page{Kind: KindHome}
|
||||||
n.RSSLink = "rssLink"
|
n.RSSLink = "rssLink"
|
||||||
|
|
||||||
if !this.assertFunc(n) {
|
if !this.assertFunc(n) {
|
||||||
|
@ -1281,14 +1281,14 @@ func TestIndexPageSimpleMethods(t *testing.T) {
|
||||||
func TestPageType(t *testing.T) {
|
func TestPageType(t *testing.T) {
|
||||||
|
|
||||||
// Add tests for these constants to make sure they don't change
|
// Add tests for these constants to make sure they don't change
|
||||||
require.Equal(t, PageType("page"), PagePage)
|
require.Equal(t, Kind("page"), KindPage)
|
||||||
require.Equal(t, PageType("home"), PageHome)
|
require.Equal(t, Kind("home"), KindHome)
|
||||||
require.Equal(t, PageType("section"), PageSection)
|
require.Equal(t, Kind("section"), KindSection)
|
||||||
require.Equal(t, PageType("taxonomy"), PageTaxonomy)
|
require.Equal(t, Kind("taxonomy"), KindTaxonomy)
|
||||||
require.Equal(t, PageType("taxonomyTerm"), PageTaxonomyTerm)
|
require.Equal(t, Kind("taxonomyTerm"), KindTaxonomyTerm)
|
||||||
|
|
||||||
require.False(t, PagePage.IsNode())
|
require.False(t, KindPage.IsNode())
|
||||||
require.True(t, PageHome.IsNode())
|
require.True(t, KindHome.IsNode())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChompBOM(t *testing.T) {
|
func TestChompBOM(t *testing.T) {
|
||||||
|
|
|
@ -260,8 +260,8 @@ func splitPageGroups(pageGroups PagesGroup, size int) []paginatedElement {
|
||||||
// Paginator gets this Node's paginator if it's already created.
|
// Paginator gets this Node's paginator if it's already created.
|
||||||
// If it's not, one will be created with all pages in Data["Pages"].
|
// If it's not, one will be created with all pages in Data["Pages"].
|
||||||
func (n *Page) Paginator(options ...interface{}) (*Pager, error) {
|
func (n *Page) Paginator(options ...interface{}) (*Pager, error) {
|
||||||
if !n.PageType.IsNode() {
|
if !n.Kind.IsNode() {
|
||||||
return nil, fmt.Errorf("Paginators not supported for pages of type %q (%q)", n.PageType, n.Title)
|
return nil, fmt.Errorf("Paginators not supported for pages of type %q (%q)", n.Kind, n.Title)
|
||||||
}
|
}
|
||||||
pagerSize, err := resolvePagerSize(options...)
|
pagerSize, err := resolvePagerSize(options...)
|
||||||
|
|
||||||
|
@ -303,8 +303,8 @@ func (n *Page) Paginator(options ...interface{}) (*Pager, error) {
|
||||||
// If it's not, one will be created with the qiven sequence.
|
// If it's not, one will be created with the qiven sequence.
|
||||||
// Note that repeated calls will return the same result, even if the sequence is different.
|
// Note that repeated calls will return the same result, even if the sequence is different.
|
||||||
func (n *Page) Paginate(seq interface{}, options ...interface{}) (*Pager, error) {
|
func (n *Page) Paginate(seq interface{}, options ...interface{}) (*Pager, error) {
|
||||||
if !n.PageType.IsNode() {
|
if !n.Kind.IsNode() {
|
||||||
return nil, fmt.Errorf("Paginators not supported for pages of type %q (%q)", n.PageType, n.Title)
|
return nil, fmt.Errorf("Paginators not supported for pages of type %q (%q)", n.Kind, n.Title)
|
||||||
}
|
}
|
||||||
|
|
||||||
pagerSize, err := resolvePagerSize(options...)
|
pagerSize, err := resolvePagerSize(options...)
|
||||||
|
|
|
@ -1533,8 +1533,8 @@ func (s *Site) assembleSections() {
|
||||||
s.Sections = make(Taxonomy)
|
s.Sections = make(Taxonomy)
|
||||||
s.Info.Sections = s.Sections
|
s.Info.Sections = s.Sections
|
||||||
// TODO(bep) np check these vs the caches
|
// TODO(bep) np check these vs the caches
|
||||||
regularPages := s.findPagesByNodeType(PagePage)
|
regularPages := s.findPagesByNodeType(KindPage)
|
||||||
sectionPages := s.findPagesByNodeType(PageSection)
|
sectionPages := s.findPagesByNodeType(KindSection)
|
||||||
|
|
||||||
for i, p := range regularPages {
|
for i, p := range regularPages {
|
||||||
s.Sections.add(p.Section(), WeightedPage{regularPages[i].Weight, regularPages[i]}, s.Info.preserveTaxonomyNames)
|
s.Sections.add(p.Section(), WeightedPage{regularPages[i].Weight, regularPages[i]}, s.Info.preserveTaxonomyNames)
|
||||||
|
@ -1561,14 +1561,14 @@ func (s *Site) assembleSections() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) nodeTypeFromSections(sections []string) PageType {
|
func (s *Site) nodeTypeFromSections(sections []string) Kind {
|
||||||
if _, isTaxonomy := s.Taxonomies[sections[0]]; isTaxonomy {
|
if _, isTaxonomy := s.Taxonomies[sections[0]]; isTaxonomy {
|
||||||
if len(sections) == 1 {
|
if len(sections) == 1 {
|
||||||
return PageTaxonomyTerm
|
return KindTaxonomyTerm
|
||||||
}
|
}
|
||||||
return PageTaxonomy
|
return KindTaxonomy
|
||||||
}
|
}
|
||||||
return PageSection
|
return KindSection
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) preparePages() error {
|
func (s *Site) preparePages() error {
|
||||||
|
@ -1662,7 +1662,7 @@ func (s *Site) Stats() {
|
||||||
// This will return nil when no page could be found.
|
// This will return nil when no page could be found.
|
||||||
//
|
//
|
||||||
// The valid page types are: home, section, taxonomy and taxonomyTerm
|
// The valid page types are: home, section, taxonomy and taxonomyTerm
|
||||||
func (s *SiteInfo) GetPage(typ PageType, path ...string) *Page {
|
func (s *SiteInfo) GetPage(typ Kind, path ...string) *Page {
|
||||||
return s.getPage(typ, path...)
|
return s.getPage(typ, path...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,14 +67,14 @@ func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.Wa
|
||||||
for p := range pages {
|
for p := range pages {
|
||||||
targetPath := p.TargetPath()
|
targetPath := p.TargetPath()
|
||||||
layouts := p.layouts()
|
layouts := p.layouts()
|
||||||
jww.DEBUG.Printf("Render %s to %q with layouts %q", p.PageType, targetPath, layouts)
|
jww.DEBUG.Printf("Render %s to %q with layouts %q", p.Kind, targetPath, layouts)
|
||||||
|
|
||||||
if err := s.renderAndWritePage("page "+p.FullFilePath(), targetPath, p, s.appendThemeTemplates(layouts)...); err != nil {
|
if err := s.renderAndWritePage("page "+p.FullFilePath(), targetPath, p, s.appendThemeTemplates(layouts)...); err != nil {
|
||||||
results <- err
|
results <- err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Taxonomy terms have no page set to paginate, so skip that for now.
|
// Taxonomy terms have no page set to paginate, so skip that for now.
|
||||||
if p.PageType.IsNode() && p.PageType != PageTaxonomyTerm {
|
if p.IsNode() && p.Kind != KindTaxonomyTerm {
|
||||||
if err := s.renderPaginator(p); err != nil {
|
if err := s.renderPaginator(p); err != nil {
|
||||||
results <- err
|
results <- err
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ func (s *Site) render404() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
p := s.newNodePage(page404)
|
p := s.newNodePage(kind404)
|
||||||
p.Title = "404 Page not found"
|
p.Title = "404 Page not found"
|
||||||
p.Data["Pages"] = s.Pages
|
p.Data["Pages"] = s.Pages
|
||||||
p.Pages = s.Pages
|
p.Pages = s.Pages
|
||||||
|
@ -181,12 +181,12 @@ func (s *Site) renderSitemap() error {
|
||||||
|
|
||||||
sitemapDefault := parseSitemap(viper.GetStringMap("sitemap"))
|
sitemapDefault := parseSitemap(viper.GetStringMap("sitemap"))
|
||||||
|
|
||||||
n := s.newNodePage(pageSitemap)
|
n := s.newNodePage(kindSitemap)
|
||||||
|
|
||||||
// Include all pages (regular, home page, taxonomies etc.)
|
// Include all pages (regular, home page, taxonomies etc.)
|
||||||
pages := s.Pages
|
pages := s.Pages
|
||||||
|
|
||||||
page := s.newNodePage(pageSitemap)
|
page := s.newNodePage(kindSitemap)
|
||||||
page.URLPath.URL = ""
|
page.URLPath.URL = ""
|
||||||
page.Sitemap.ChangeFreq = sitemapDefault.ChangeFreq
|
page.Sitemap.ChangeFreq = sitemapDefault.ChangeFreq
|
||||||
page.Sitemap.Priority = sitemapDefault.Priority
|
page.Sitemap.Priority = sitemapDefault.Priority
|
||||||
|
@ -224,7 +224,7 @@ func (s *Site) renderRobotsTXT() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
n := s.newNodePage(pageRobotsTXT)
|
n := s.newNodePage(kindRobotsTXT)
|
||||||
n.Data["Pages"] = s.Pages
|
n.Data["Pages"] = s.Pages
|
||||||
n.Pages = s.Pages
|
n.Pages = s.Pages
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue