summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-03 17:27:40 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-08 20:13:39 +0200
commit7ff0a8ee9fe8d710d407e57faf1fda43bd635f28 (patch)
tree4baa7d913f735cc1089e465b51ff007014bfe25a /hugolib
parentdf374851a0683f1446f33a4afef74c42f7d3eaaf (diff)
Simplify page tree logic
This is preparation for #6041. For historic reasons, the code for bulding the section tree and the taxonomies were very much separate. This works, but makes it hard to extend, maintain, and possibly not so fast as it could be. This simplification also introduces 3 slightly breaking changes, which I suspect most people will be pleased about. See referenced issues: This commit also switches the radix tree dependency to a mutable implementation: github.com/armon/go-radix. Fixes #6154 Fixes #6153 Fixes #6152
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/hugo_sites.go154
-rw-r--r--hugolib/hugo_sites_build.go67
-rw-r--r--hugolib/hugo_sites_build_test.go74
-rw-r--r--hugolib/hugo_sites_rebuild_test.go2
-rw-r--r--hugolib/hugo_smoke_test.go6
-rw-r--r--hugolib/page.go109
-rw-r--r--hugolib/page__common.go12
-rw-r--r--hugolib/page__data.go24
-rw-r--r--hugolib/page__paginator.go12
-rw-r--r--hugolib/page__per_output.go3
-rw-r--r--hugolib/page__tree.go16
-rw-r--r--hugolib/page_test.go1
-rw-r--r--hugolib/pagebundler_test.go4
-rw-r--r--hugolib/pagecollections.go200
-rw-r--r--hugolib/pages_capture.go9
-rw-r--r--hugolib/pages_map.go367
-rw-r--r--hugolib/site.go198
-rw-r--r--hugolib/site_sections.go212
-rw-r--r--hugolib/site_sections_test.go24
-rw-r--r--hugolib/taxonomy.go94
-rw-r--r--hugolib/taxonomy_test.go2
-rw-r--r--hugolib/testhelpers_test.go1
22 files changed, 763 insertions, 828 deletions
diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go
index 6ad871564..987144f1d 100644
--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -14,15 +14,13 @@
package hugolib
import (
- "fmt"
"io"
- "path"
"path/filepath"
"sort"
"strings"
"sync"
- radix "github.com/hashicorp/go-immutable-radix"
+ radix "github.com/armon/go-radix"
"github.com/gohugoio/hugo/output"
"github.com/gohugoio/hugo/parser/metadecoders"
@@ -623,118 +621,6 @@ func (h *HugoSites) renderCrossSitesArtifacts() error {
s.siteCfg.sitemap.Filename, h.toSiteInfos(), smLayouts...)
}
-// createMissingPages creates home page, taxonomies etc. that isnt't created as an
-// effect of having a content file.
-func (h *HugoSites) createMissingPages() error {
-
- for _, s := range h.Sites {
- if s.isEnabled(page.KindHome) {
- // home pages
- homes := s.findWorkPagesByKind(page.KindHome)
- if len(homes) > 1 {
- panic("Too many homes")
- }
- var home *pageState
- if len(homes) == 0 {
- home = s.newPage(page.KindHome)
- s.workAllPages = append(s.workAllPages, home)
- } else {
- home = homes[0]
- }
-
- s.home = home
- }
-
- // Will create content-less root sections.
- newSections := s.assembleSections()
- s.workAllPages = append(s.workAllPages, newSections...)
-
- taxonomyTermEnabled := s.isEnabled(page.KindTaxonomyTerm)
- taxonomyEnabled := s.isEnabled(page.KindTaxonomy)
-
- // taxonomy list and terms pages
- taxonomies := s.Language().GetStringMapString("taxonomies")
- if len(taxonomies) > 0 {
- taxonomyPages := s.findWorkPagesByKind(page.KindTaxonomy)
- taxonomyTermsPages := s.findWorkPagesByKind(page.KindTaxonomyTerm)
-
- // Make them navigable from WeightedPage etc.
- for _, p := range taxonomyPages {
- ni := p.getTaxonomyNodeInfo()
- if ni == nil {
- // This can be nil for taxonomies, e.g. an author,
- // with a content file, but no actual usage.
- // Create one.
- sections := p.SectionsEntries()
- if len(sections) < 2 {
- // Invalid state
- panic(fmt.Sprintf("invalid taxonomy state for %q with sections %v", p.pathOrTitle(), sections))
- }
- ni = p.s.taxonomyNodes.GetOrAdd(sections[0], path.Join(sections[1:]...))
- }
- ni.TransferValues(p)
- }
- for _, p := range taxonomyTermsPages {
- p.getTaxonomyNodeInfo().TransferValues(p)
- }
-
- for _, plural := range taxonomies {
- if taxonomyTermEnabled {
- foundTaxonomyTermsPage := false
- for _, p := range taxonomyTermsPages {
- if p.SectionsPath() == plural {
- foundTaxonomyTermsPage = true
- break
- }
- }
-
- if !foundTaxonomyTermsPage {
- n := s.newPage(page.KindTaxonomyTerm, plural)
- n.getTaxonomyNodeInfo().TransferValues(n)
- s.workAllPages = append(s.workAllPages, n)
- }
- }
-
- if taxonomyEnabled {
- for termKey := range s.Taxonomies[plural] {
-
- foundTaxonomyPage := false
-
- for _, p := range taxonomyPages {
- sectionsPath := p.SectionsPath()
-
- if !strings.HasPrefix(sectionsPath, plural) {
- continue
- }
-
- singularKey := strings.TrimPrefix(sectionsPath, plural)
- singularKey = strings.TrimPrefix(singularKey, "/")
-
- if singularKey == termKey {
- foundTaxonomyPage = true
- break
- }
- }
-
- if !foundTaxonomyPage {
- info := s.taxonomyNodes.Get(plural, termKey)
- if info == nil {
- panic("no info found")
- }
-
- n := s.newTaxonomyPage(info.term, info.plural, info.termKey)
- info.TransferValues(n)
- s.workAllPages = append(s.workAllPages, n)
- }
- }
- }
- }
- }
- }
-
- return nil
-}
-
func (h *HugoSites) removePageByFilename(filename string) {
for _, s := range h.Sites {
s.removePageFilename(filename)
@@ -742,23 +628,6 @@ func (h *HugoSites) removePageByFilename(filename string) {
}
func (h *HugoSites) createPageCollections() error {
- for _, s := range h.Sites {
- for _, p := range s.rawAllPages {
- if !s.isEnabled(p.Kind()) {
- continue
- }
-
- shouldBuild := s.shouldBuild(p)
- s.buildStats.update(p)
- if shouldBuild {
- if p.m.headless {
- s.headlessPages = append(s.headlessPages, p)
- } else {
- s.workAllPages = append(s.workAllPages, p)
- }
- }
- }
- }
allPages := newLazyPagesFactory(func() page.Pages {
var pages page.Pages
@@ -950,8 +819,7 @@ type contentChangeMap struct {
mu sync.RWMutex
// Holds directories with leaf bundles.
- leafBundles *radix.Tree
- leafBundlesTxn *radix.Txn
+ leafBundles *radix.Tree
// Holds directories with branch bundles.
branchBundles map[string]bool
@@ -969,18 +837,6 @@ type contentChangeMap struct {
symContent map[string]map[string]bool
}
-func (m *contentChangeMap) start() {
- m.mu.Lock()
- m.leafBundlesTxn = m.leafBundles.Txn()
- m.mu.Unlock()
-}
-
-func (m *contentChangeMap) stop() {
- m.mu.Lock()
- m.leafBundles = m.leafBundlesTxn.Commit()
- m.mu.Unlock()
-}
-
func (m *contentChangeMap) add(filename string, tp bundleDirType) {
m.mu.Lock()
dir := filepath.Dir(filename) + helpers.FilePathSeparator
@@ -989,7 +845,7 @@ func (m *contentChangeMap) add(filename string, tp bundleDirType) {
case bundleBranch:
m.branchBundles[dir] = true
case bundleLeaf:
- m.leafBundlesTxn.Insert([]byte(dir), true)
+ m.leafBundles.Insert(dir, true)
default:
panic("invalid bundle type")
}
@@ -1012,8 +868,8 @@ func (m *contentChangeMap) resolveAndRemove(filename string) (string, string, bu
return dir, dir, bundleBranch
}
- if key, _, found := m.leafBundles.Root().LongestPrefix([]byte(dir)); found {
- m.leafBundlesTxn.Delete(key)
+ if key, _, found := m.leafBundles.LongestPrefix(dir); found {
+ m.leafBundles.Delete(key)
dir = string(key)
return dir, dir, bundleLeaf
}
diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go
index d20932599..82a189a50 100644
--- a/hugolib/hugo_sites_build.go
+++ b/hugolib/hugo_sites_build.go
@@ -18,7 +18,6 @@ import (
"context"
"fmt"
"runtime/trace"
- "sort"
"github.com/gohugoio/hugo/output"
@@ -31,6 +30,7 @@ import (
// Build builds all sites. If filesystem events are provided,
// this is considered to be a potential partial rebuild.
func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error {
+
if h.running {
// Make sure we don't trigger rebuilds in parallel.
h.runningMu.Lock()
@@ -75,25 +75,29 @@ func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error {
if !config.PartialReRender {
prepare := func() error {
- for _, s := range h.Sites {
- s.Deps.BuildStartListeners.Notify()
- }
-
- if len(events) > 0 {
- // Rebuild
- if err := h.initRebuild(conf); err != nil {
- return errors.Wrap(err, "initRebuild")
+ init := func(conf *BuildCfg) error {
+ for _, s := range h.Sites {
+ s.Deps.BuildStartListeners.Notify()
}
- } else {
- if err := h.initSites(conf); err != nil {
- return errors.Wrap(err, "initSites")
+
+ if len(events) > 0 {
+ // Rebuild
+ if err := h.initRebuild(conf); err != nil {
+ return errors.Wrap(err, "initRebuild")
+ }
+ } else {
+ if err := h.initSites(conf); err != nil {
+ return errors.Wrap(err, "initSites")
+ }
}
+
+ return nil
}
var err error
f := func() {
- err = h.process(conf, events...)
+ err = h.process(conf, init, events...)
}
trace.WithRegion(ctx, "process", f)
if err != nil {
@@ -195,7 +199,7 @@ func (h *HugoSites) initRebuild(config *BuildCfg) error {
}
for _, s := range h.Sites {
- s.resetBuildState()
+ s.resetBuildState(config.whatChanged.source)
}
h.reset(config)
@@ -205,7 +209,7 @@ func (h *HugoSites) initRebuild(config *BuildCfg) error {
return nil
}
-func (h *HugoSites) process(config *BuildCfg, events ...fsnotify.Event) error {
+func (h *HugoSites) process(config *BuildCfg, init func(config *BuildCfg) error, events ...fsnotify.Event) error {
// We should probably refactor the Site and pull up most of the logic from there to here,
// but that seems like a daunting task.
// So for now, if there are more than one site (language),
@@ -215,9 +219,7 @@ func (h *HugoSites) process(config *BuildCfg, events ...fsnotify.Event) error {
if len(events) > 0 {
// This is a rebuild
- changed, err := firstSite.processPartial(events)
- config.whatChanged = &changed
- return err
+ return firstSite.processPartial(config, init, events)
}
return firstSite.process(*config)
@@ -235,26 +237,27 @@ func (h *HugoSites) assemble(config *BuildCfg) error {
}
}
- if err := h.createPageCollections(); err != nil {
- return err
+ if !config.whatChanged.source {
+ return nil
}
- if config.whatChanged.source {
- for _, s := range h.Sites {
- if err := s.assembleTaxonomies(); err != nil {
- return err
- }
+ for _, s := range h.Sites {
+ if err := s.assemblePagesMap(s); err != nil {
+ return err
+ }
+
+ if err := s.pagesMap.assembleTaxonomies(s); err != nil {
+ return err
+ }
+
+ if err := s.createWorkAllPages(); err != nil {
+ return err
}
- }
- // Create pagexs for the section pages etc. without content file.
- if err := h.createMissingPages(); err != nil {
- return err
}
- for _, s := range h.Sites {
- s.setupSitePages()
- sort.Stable(s.workAllPages)
+ if err := h.createPageCollections(); err != nil {
+ return err
}
return nil
diff --git a/hugolib/hugo_sites_build_test.go b/hugolib/hugo_sites_build_test.go
index 876f21cfa..123c27b9c 100644
--- a/hugolib/hugo_sites_build_test.go
+++ b/hugolib/hugo_sites_build_test.go
@@ -365,7 +365,6 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
require.NotNil(t, enTags["tag1"])
require.NotNil(t, frTags["FRtag1"])
b.AssertFileContent("public/fr/plaques/FRtag1/index.html", "FRtag1|Bonjour|http://example.com/blog/fr/plaques/FRtag1/")
- b.AssertFileContent("public/en/tags/tag1/index.html", "tag1|Hello|http://example.com/blog/en/tags/tag1/")
// Check Blackfriday config
require.True(t, strings.Contains(content(doc1fr), "&laquo;"), content(doc1fr))
@@ -470,13 +469,6 @@ func TestMultiSitesRebuild(t *testing.T) {
func(t *testing.T) {
assert.Len(enSite.RegularPages(), 4, "1 en removed")
- // Check build stats
- require.Equal(t, 1, enSite.buildStats.draftCount, "Draft")
- require.Equal(t, 1, enSite.buildStats.futureCount, "Future")
- require.Equal(t, 1, enSite.buildStats.expiredCount, "Expired")
- require.Equal(t, 0, frSite.buildStats.draftCount, "Draft")
- require.Equal(t, 1, frSite.buildStats.futureCount, "Future")
- require.Equal(t, 1, frSite.buildStats.expiredCount, "Expired")
},
},
{
@@ -609,70 +601,6 @@ func TestMultiSitesRebuild(t *testing.T) {
}
-func TestAddNewLanguage(t *testing.T) {
- t.Parallel()
- assert := require.New(t)
-
- b := newMultiSiteTestDefaultBuilder(t)
- b.CreateSites().Build(BuildCfg{})
-
- fs := b.Fs
-
- newConfig := multiSiteTOMLConfigTemplate + `
-
-[Languages.sv]
-weight = 15
-title = "Svenska"
-`
-
- writeNewContentFile(t, fs.Source, "Swedish Contentfile", "2016-01-01", "content/sect/doc1.sv.md", 10)
- // replace the config
- b.WithNewConfig(newConfig)
-
- sites := b.H
-
- assert.NoError(b.LoadConfig())
- err := b.H.Build(BuildCfg{NewConfig: b.Cfg})
-
- if err != nil {
- t.Fatalf("Failed to rebuild sites: %s", err)
- }
-
- require.Len(t, sites.Sites, 5, fmt.Sprintf("Len %d", len(sites.Sites)))
-
- // The Swedish site should be put in the middle (language weight=15)
- enSite := sites.Sites[0]
- svSite := sites.Sites[1]
- frSite := sites.Sites[2]
- require.True(t, enSite.language.Lang == "en", enSite.language.Lang)
- require.True(t, svSite.language.Lang == "sv", svSite.language.Lang)
- require.True(t, frSite.language.Lang == "fr", frSite.language.Lang)
-
- homeEn := enSite.getPage(page.KindHome)
- require.NotNil(t, homeEn)
- require.Len(t, homeEn.Translations(), 4)
-
- require.Equal(t, "sv", homeEn.Translations()[0].Language().Lang)
-
- require.Len(t, enSite.RegularPages(), 5)
- require.Len(t, frSite.RegularPages(), 4)
-
- // Veriy Swedish site
- require.Len(t, svSite.RegularPages(), 1)
- svPage := svSite.RegularPages()[0]
-
- require.Equal(t, "Swedish Contentfile", svPage.Title())
- require.Equal(t, "sv", svPage.Language().Lang)
- require.Len(t, svPage.Translations(), 2)
- require.Len(t, svPage.AllTranslations(), 3)
- require.Equal(t, "en", svPage.Translations()[0].Language().Lang)
-
- // Regular pages have no children
- require.Len(t, svPage.Pages(), 0)
- require.Len(t, svPage.Data().(page.Data).Pages(), 0)
-
-}
-
// https://github.com/gohugoio/hugo/issues/4706
func TestContentStressTest(t *testing.T) {
b := newTestSitesBuilder(t)
@@ -775,13 +703,13 @@ END
}
func checkContent(s *sitesBuilder, filename string, matches ...string) {
+ s.T.Helper()
content := readDestination(s.T, s.Fs, filename)
for _, match := range matches {
if !strings.Contains(content, match) {
s.Fatalf("No match for %q in content for %s\n%q", match, filename, content)
}
}
-
}
func TestTranslationsFromContentToNonContent(t *testing.T) {
diff --git a/hugolib/hugo_sites_rebuild_test.go b/hugolib/hugo_sites_rebuild_test.go
index 4a81fe950..e36c1a1d4 100644
--- a/hugolib/hugo_sites_rebuild_test.go
+++ b/hugolib/hugo_sites_rebuild_test.go
@@ -54,7 +54,7 @@ Content.
{{ range (.Paginate .Site.RegularPages).Pages }}
* Page Paginate: {{ .Title }}|Summary: {{ .Summary }}|Content: {{ .Content }}
{{ end }}
-{{ range .Pages }}
+{{ range .Site.RegularPages }}
* Page Pages: {{ .Title }}|Summary: {{ .Summary }}|Content: {{ .Content }}
{{ end }}
`)
diff --git a/hugolib/hugo_smoke_test.go b/hugolib/hugo_smoke_test.go
index d5b8861ce..a6a951fa7 100644
--- a/hugolib/hugo_smoke_test.go
+++ b/hugolib/hugo_smoke_test.go
@@ -143,8 +143,8 @@ Some **Markdown** in JSON shortcode.
const (
commonPageTemplate = `|{{ .Kind }}|{{ .Title }}|{{ .Path }}|{{ .Summary }}|{{ .Content }}|RelPermalink: {{ .RelPermalink }}|WordCount: {{ .WordCount }}|Pages: {{ .Pages }}|Data Pages: Pages({{ len .Data.Pages }})|Resources: {{ len .Resources }}|Summary: {{ .Summary }}`
commonPaginatorTemplate = `|Paginator: {{ with .Paginator }}{{ .PageNumber }}{{ else }}NIL{{ end }}`
- commonListTemplateNoPaginator = `|{{ range $i, $e := (.Pages | first 1) }}|Render {{ $i }}: {{ .Kind }}|{{ .Render "li" }}|{{ end }}|Site params: {{ $.Site.Params.hugo }}|RelPermalink: {{ .RelPermalink }}`
- commonListTemplate = commonPaginatorTemplate + `|{{ range $i, $e := (.Pages | first 1) }}|Render {{ $i }}: {{ .Kind }}|{{ .Render "li" }}|{{ end }}|Site params: {{ $.Site.Params.hugo }}|RelPermalink: {{ .RelPermalink }}`
+ commonListTemplateNoPaginator = `|{{ $pages := .Pages }}{{ if .IsHome }}{{ $pages = .Site.RegularPages }}{{ end }}{{ range $i, $e := ($pages | first 1) }}|Render {{ $i }}: {{ .Kind }}|{{ .Render "li" }}|{{ end }}|Site params: {{ $.Site.Params.hugo }}|RelPermalink: {{ .RelPermalink }}`
+ commonListTemplate = commonPaginatorTemplate + `|{{ $pages := .Pages }}{{ if .IsHome }}{{ $pages = .Site.RegularPages }}{{ end }}{{ range $i, $e := ($pages | first 1) }}|Render {{ $i }}: {{ .Kind }}|{{ .Render "li" }}|{{ end }}|Site params: {{ $.Site.Params.hugo }}|RelPermalink: {{ .RelPermalink }}`
commonShortcodeTemplate = `|{{ .Name }}|{{ .Ordinal }}|{{ .Page.Summary }}|{{ .Page.Content }}|WordCount: {{ .Page.WordCount }}`
prevNextTemplate = `|Prev: {{ with .Prev }}{{ .RelPermalink }}{{ end }}|Next: {{ with .Next }}{{ .RelPermalink }}{{ end }}`
prevNextInSectionTemplate = `|PrevInSection: {{ with .PrevInSection }}{{ .RelPermalink }}{{ end }}|NextInSection: {{ with .NextInSection }}{{ .RelPermalink }}{{ end }}`
@@ -193,7 +193,7 @@ Some **Markdown** in JSON shortcode.
b.AssertFileContent("public/index.html",
"home|In English",
"Site params: Rules",
- "Pages: Pages(18)|Data Pages: Pages(18)",
+ "Pages: Pages(6)|Data Pages: Pages(6)",
"Paginator: 1",
"First Site: In English",
"RelPermalink: /",
diff --git a/hugolib/page.go b/hugolib/page.go
index 676cba762..8dda33009 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -23,6 +23,8 @@ import (
"sort"
"strings"
+ "github.com/gohugoio/hugo/common/maps"
+
"github.com/gohugoio/hugo/hugofs/files"
"github.com/bep/gitmap"
@@ -121,31 +123,66 @@ func (p *pageState) MarshalJSON() ([]byte, error) {
return page.MarshalPageToJSON(p)
}
-func (p *pageState) Pages() page.Pages {
- p.pagesInit.Do(func() {
- if p.pages != nil {
- return
- }
+func (p *pageState) getPages() page.Pages {
+ b := p.bucket
+ if b == nil {
+ return nil
+ }
+ return b.getPages()
+}
+func (p *pageState) getPagesAndSections() page.Pages {
+ b := p.bucket
+ if b == nil {
+ return nil
+ }
+ return b.getPagesAndSections()
+}
+
+// TODO(bep) cm add a test
+func (p *pageState) RegularPages() page.Pages {
+ p.regularPagesInit.Do(func() {
var pages page.Pages
switch p.Kind() {
case page.KindPage:
- case page.KindHome:
- pages = p.s.RegularPages()
+ case page.KindSection, page.KindHome, page.KindTaxonomyTerm:
+ pages = p.getPages()
case page.KindTaxonomy:
- termInfo := p.getTaxonomyNodeInfo()
- taxonomy := p.s.Taxonomies[termInfo.plural].Get(termInfo.termKey)
- pages = taxonomy.Pages()
- case page.KindTaxonomyTerm:
- plural := p.getTaxonomyNodeInfo().plural
- // A list of all page.KindTaxonomy pages with matching plural
- for _, p := range p.s.findPagesByKind(page.KindTaxonomy) {
- if p.SectionsEntries()[0] == plural {
+ all := p.Pages()
+ for _, p := range all {
+ if p.IsPage() {
pages = append(pages, p)
}
}
- case kind404, kindSitemap, kindRobotsTXT:
+ default:
+ pages = p.s.RegularPages()
+ }
+
+ p.regularPages = pages
+
+ })
+
+ return p.regularPages
+}
+
+func (p *pageState) Pages() page.Pages {
+ p.pagesInit.Do(func() {
+ var pages page.Pages
+
+ switch p.Kind() {
+ case page.KindPage:
+ case page.KindSection, page.KindHome:
+ pages = p.getPagesAndSections()
+ case page.KindTaxonomy:
+ termInfo := p.bucket
+ plural := maps.GetString(termInfo.meta, "plural")
+ term := maps.GetString(termInfo.meta, "termKey")
+ taxonomy := p.s.Taxonomies[plural].Get(term)
+ pages = taxonomy.Pages()
+ case page.KindTaxonomyTerm:
+ pages = p.getPagesAndSections()
+ default:
pages = p.s.Pages()
}
@@ -295,10 +332,9 @@ func (p *pageState) getLayoutDescriptor() output.LayoutDescriptor {
if len(sections) > 0 {
section = sections[0]
}
- case page.KindTaxonomyTerm:
- section = p.getTaxonomyNodeInfo().singular
- case page.KindTaxonomy:
- section = p.getTaxonomyNodeInfo().parent.singular
+ case page.KindTaxonomyTerm, page.KindTaxonomy:
+ section = maps.GetString(p.bucket.meta, "singular")
+
default:
}
@@ -359,11 +395,6 @@ func (p *pageState) initPage() error {
return nil
}
-func (p *pageState) setPages(pages page.Pages) {
- page.SortByDefault(pages)
- p.pages = pages
-}
-
func (p *pageState) renderResources() (err error) {
p.resourcesPublishInit.Do(func() {
var toBeDeleted []int
@@ -489,13 +520,6 @@ func (p *pageState) addResources(r ...resource.Resource) {
p.resources = append(p.resources, r...)
}
-func (p *pageState) addSectionToParent() {
- if p.parent == nil {
- return
- }
- p.parent.subSections = append(p.parent.subSections, p)
-}
-
func (p *pageState) mapContent(meta *pageMeta) error {
s := p.shortcodeState
@@ -743,27 +767,6 @@ func (p *pageState) shiftToOutputFormat(isRenderingSite bool, idx int) error {
return nil
}
-func (p *pageState) getTaxonomyNodeInfo() *taxonomyNodeInfo {
- info := p.s.taxonomyNodes.Get(p.SectionsEntries()...)
-
- if info == nil {
- // There can be unused content pages for taxonomies (e.g. author that
- // has not written anything, yet), and these will not have a taxonomy
- // node created in the assemble taxonomies step.
- return nil
- }
-
- return info
-
-}
-
-func (p *pageState) sortParentSections() {
- if p.parent == nil {
- return
- }
- page.SortByDefault(p.parent.subSections)
-}
-
// sourceRef returns the reference used by GetPage and ref/relref shortcodes to refer to
// this page. It is prefixed with a "/".
//
diff --git a/hugolib/page__common.go b/hugolib/page__common.go
index f9ceee8c9..cf554bb40 100644
--- a/hugolib/page__common.go
+++ b/hugolib/page__common.go
@@ -30,6 +30,8 @@ type pageCommon struct {
s *Site
m *pageMeta
+ bucket *pagesMapBucket
+
// Laziliy initialized dependencies.
init *lazy.Init
@@ -101,17 +103,17 @@ type pageCommon struct {
translationKey string
translationKeyInit sync.Once
- // Will only be set for sections and regular pages.
+ // Will only be set for bundled pages.
parent *pageState
- // Will only be set for section pages and the home page.
- subSections page.Pages
-
// Set in fast render mode to force render a given page.
forceRender bool
}
type pagePages struct {
- pages page.Pages
pagesInit sync.Once
+ pages page.Pages
+
+ regularPagesInit sync.Once
+ regularPages page.Pages
}
diff --git a/hugolib/page__data.go b/hugolib/page__data.go
index 79a64931b..8bc818a00 100644
--- a/hugolib/page__data.go
+++ b/hugolib/page__data.go
@@ -16,6 +16,8 @@ package hugolib
import (
"sync"
+ "github.com/gohugoio/hugo/common/maps"
+
"github.com/gohugoio/hugo/resources/page"
)
@@ -36,22 +38,22 @@ func (p *pageData) Data() interface{} {
switch p.Kind() {
case page.KindTaxonomy:
- termInfo := p.getTaxonomyNodeInfo()
- pluralInfo := termInfo.parent
+ bucket := p.bucket
+ meta := bucket.meta
+ plural := maps.GetString(meta, "plural")
+ singular := maps.GetString(meta, "singular")
- singular := pluralInfo.singular
- plural := pluralInfo.plural
- term := termInfo.term
- taxonomy := p.s.Taxonomies[plural].Get(termInfo.termKey)
+ taxonomy := p.s.Taxonomies[plural].Get(maps.GetString(meta, "termKey"))
p.data[singular] = taxonomy
- p.data["Singular"] = singular
+ p.data["Singular"] = meta["singular"]
p.data["Plural"] = plural
- p.data["Term"] = term
+ p.data["Term"] = meta["term"]
case page.KindTaxonomyTerm:
- info := p.getTaxonomyNodeInfo()
- plural := info.plural
- singular := info.singular
+ bucket := p.bucket
+ meta := bucket.meta
+ plural := maps.GetString(meta, "plural")
+ singular := maps.GetString(meta, "singular")
p.data["Singular"] = singular
p.data["Plural"] = plural
diff --git