summaryrefslogtreecommitdiffstats
path: root/hugolib/site_new.go
diff options
context:
space:
mode:
Diffstat (limited to 'hugolib/site_new.go')
-rw-r--r--hugolib/site_new.go206
1 files changed, 133 insertions, 73 deletions
diff --git a/hugolib/site_new.go b/hugolib/site_new.go
index da9d19f21..ddf45c286 100644
--- a/hugolib/site_new.go
+++ b/hugolib/site_new.go
@@ -1,4 +1,4 @@
-// Copyright 2023 The Hugo Authors. All rights reserved.
+// Copyright 2024 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.
@@ -22,8 +22,8 @@ import (
"sort"
"time"
- radix "github.com/armon/go-radix"
"github.com/bep/logg"
+ "github.com/gohugoio/hugo/cache/dynacache"
"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/common/maps"
@@ -31,6 +31,7 @@ import (
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/config/allconfig"
"github.com/gohugoio/hugo/deps"
+ "github.com/gohugoio/hugo/hugolib/doctree"
"github.com/gohugoio/hugo/identity"
"github.com/gohugoio/hugo/langs"
"github.com/gohugoio/hugo/langs/i18n"
@@ -39,9 +40,9 @@ import (
"github.com/gohugoio/hugo/navigation"
"github.com/gohugoio/hugo/output"
"github.com/gohugoio/hugo/publisher"
- "github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/resources/page/pagemeta"
+ "github.com/gohugoio/hugo/resources/page/siteidentities"
"github.com/gohugoio/hugo/resources/resource"
"github.com/gohugoio/hugo/tpl"
"github.com/gohugoio/hugo/tpl/tplimpl"
@@ -50,8 +51,10 @@ import (
var _ page.Site = (*Site)(nil)
type Site struct {
- conf *allconfig.Config
- language *langs.Language
+ conf *allconfig.Config
+ language *langs.Language
+ languagei int
+ pageMap *pageMap
// The owning container.
h *HugoSites
@@ -59,12 +62,10 @@ type Site struct {
*deps.Deps
// Page navigation.
- *PageCollections
+ *pageFinder
taxonomies page.TaxonomyList
menus navigation.Menus
- siteBucket *pagesMapBucket
-
// Shortcut to the home page. Note that this may be nil if
// home page, for some odd reason, is disabled.
home *pageState
@@ -93,7 +94,7 @@ type Site struct {
func (s *Site) Debug() {
fmt.Println("Debugging site", s.Lang(), "=>")
- fmt.Println(s.pageMap.testDump())
+ // fmt.Println(s.pageMap.testDump())
}
// NewHugoSites creates HugoSites from the given config.
@@ -127,10 +128,13 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) {
logger = loggers.New(logOpts)
}
+ memCache := dynacache.New(dynacache.Options{Running: conf.Running(), Log: logger})
+
firstSiteDeps := &deps.Deps{
Fs: cfg.Fs,
Log: logger,
Conf: conf,
+ MemCache: memCache,
TemplateProvider: tplimpl.DefaultTemplateProvider,
TranslationProvider: i18n.NewTranslationProvider(),
}
@@ -142,14 +146,40 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) {
confm := cfg.Configs
var sites []*Site
+ ns := &contentNodeShifter{
+ numLanguages: len(confm.Languages),
+ }
+
+ treeConfig := doctree.Config[contentNodeI]{
+ Shifter: ns,
+ }
+
+ pageTrees := &pageTrees{
+ treePages: doctree.New(
+ treeConfig,
+ ),
+ treeResources: doctree.New(
+ treeConfig,
+ ),
+ treeTaxonomyEntries: doctree.NewTreeShiftTree[*weightedContentNode](doctree.DimensionLanguage.Index(), len(confm.Languages)),
+ }
+
+ pageTrees.treePagesResources = doctree.WalkableTrees[contentNodeI]{
+ pageTrees.treePages,
+ pageTrees.treeResources,
+ }
+
+ pageTrees.resourceTrees = doctree.MutableTrees{
+ pageTrees.treeResources,
+ }
+
for i, confp := range confm.ConfigLangs() {
language := confp.Language()
- if confp.IsLangDisabled(language.Lang) {
+ if language.Disabled {
continue
}
k := language.Lang
conf := confm.LanguageConfigMap[k]
-
frontmatterHandler, err := pagemeta.NewFrontmatterHandler(firstSiteDeps.Log, conf.Frontmatter)
if err != nil {
return nil, err
@@ -158,11 +188,9 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) {
langs.SetParams(language, conf.Params)
s := &Site{
- conf: conf,
- language: language,
- siteBucket: &pagesMapBucket{
- cascade: conf.Cascade.Config,
- },
+ conf: conf,
+ language: language,
+ languagei: i,
frontmatterHandler: frontmatterHandler,
}
@@ -177,20 +205,9 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) {
s.Deps = d
}
- // Site deps start.
- var taxonomiesConfig taxonomiesConfig = conf.Taxonomies
- pm := &pageMap{
- contentMap: newContentMap(contentMapConfig{
- lang: k,
- taxonomyConfig: taxonomiesConfig.Values(),
- taxonomyDisabled: !conf.IsKindEnabled(kinds.KindTerm),
- taxonomyTermDisabled: !conf.IsKindEnabled(kinds.KindTaxonomy),
- pageDisabled: !conf.IsKindEnabled(kinds.KindPage),
- }),
- s: s,
- }
+ s.pageMap = newPageMap(i, s, memCache, pageTrees)
- s.PageCollections = newPageCollections(pm)
+ s.pageFinder = newPageFinder(s.pageMap)
s.siteRefLinker, err = newSiteRefLinker(s)
if err != nil {
return nil, err
@@ -217,17 +234,26 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) {
return nil, errors.New("no sites to build")
}
- // Sort the sites by language weight (if set) or lang.
+ // Pull the default content language to the top, then sort the sites by language weight (if set) or lang.
+ defaultContentLanguage := confm.Base.DefaultContentLanguage
sort.Slice(sites, func(i, j int) bool {
li := sites[i].language
lj := sites[j].language
+ if li.Lang == defaultContentLanguage {
+ return true
+ }
+
+ if lj.Lang == defaultContentLanguage {
+ return false
+ }
+
if li.Weight != lj.Weight {
return li.Weight < lj.Weight
}
return li.Lang < lj.Lang
})
- h, err := newHugoSitesNew(cfg, firstSiteDeps, sites)
+ h, err := newHugoSites(cfg, firstSiteDeps, pageTrees, sites)
if err == nil && h == nil {
panic("hugo: newHugoSitesNew returned nil error and nil HugoSites")
}
@@ -235,29 +261,33 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) {
return h, err
}
-func newHugoSitesNew(cfg deps.DepsCfg, d *deps.Deps, sites []*Site) (*HugoSites, error) {
+func newHugoSites(cfg deps.DepsCfg, d *deps.Deps, pageTrees *pageTrees, sites []*Site) (*HugoSites, error) {
numWorkers := config.GetNumWorkerMultiplier()
- if numWorkers > len(sites) {
- numWorkers = len(sites)
- }
- var workers *para.Workers
- if numWorkers > 1 {
- workers = para.New(numWorkers)
+ numWorkersSite := numWorkers
+ if numWorkersSite > len(sites) {
+ numWorkersSite = len(sites)
}
+ workersSite := para.New(numWorkersSite)
h := &HugoSites{
- Sites: sites,
- Deps: sites[0].Deps,
- Configs: cfg.Configs,
- workers: workers,
- numWorkers: numWorkers,
+ Sites: sites,
+ Deps: sites[0].Deps,
+ Configs: cfg.Configs,
+ workersSite: workersSite,
+ numWorkersSites: numWorkers,
+ numWorkers: numWorkers,
+ pageTrees: pageTrees,
+ cachePages: dynacache.GetOrCreatePartition[string,
+ page.Pages](d.MemCache, "/pags/all",
+ dynacache.OptionsPartition{Weight: 10, ClearWhen: dynacache.ClearOnRebuild},
+ ),
+ translationKeyPages: maps.NewSliceCache[page.Page](),
currentSite: sites[0],
skipRebuildForFilenames: make(map[string]bool),
init: &hugoSitesInit{
- data: lazy.New(),
- layouts: lazy.New(),
- gitInfo: lazy.New(),
- translations: lazy.New(),
+ data: lazy.New(),
+ layouts: lazy.New(),
+ gitInfo: lazy.New(),
},
}
@@ -304,18 +334,8 @@ func newHugoSitesNew(cfg deps.DepsCfg, d *deps.Deps, sites []*Site) (*HugoSites,
donec: make(chan bool),
}
- // Only needed in server mode.
- if cfg.Configs.Base.Internal.Watch {
- h.ContentChanges = &contentChangeMap{
- pathSpec: h.PathSpec,
- symContent: make(map[string]map[string]bool),
- leafBundles: radix.New(),
- branchBundles: make(map[string]bool),
- }
- }
-
h.init.data.Add(func(context.Context) (any, error) {
- err := h.loadData(h.PathSpec.BaseFs.Data.Dirs)
+ err := h.loadData()
if err != nil {
return nil, fmt.Errorf("failed to load data: %w", err)
}
@@ -331,15 +351,6 @@ func newHugoSitesNew(cfg deps.DepsCfg, d *deps.Deps, sites []*Site) (*HugoSites,
return nil, nil
})
- h.init.translations.Add(func(context.Context) (any, error) {
- if len(h.Sites) > 1 {
- allTranslations := pagesToTranslationsMap(h.Sites)
- assignTranslationsToPages(allTranslations, h.Sites)
- }
-
- return nil, nil
- })
-
h.init.gitInfo.Add(func(context.Context) (any, error) {
err := h.loadGitInfo()
if err != nil {
@@ -422,10 +433,16 @@ func (s *Site) BaseURL() string {
}
// Returns the last modification date of the content.
+// Deprecated: Use .Lastmod instead.
func (s *Site) LastChange() time.Time {
return s.lastmod
}
+// Returns the last modification date of the content.
+func (s *Site) Lastmod() time.Time {
+ return s.lastmod
+}
+
// Returns the Params configured for this site.
func (s *Site) Params() maps.Params {
return s.conf.Params
@@ -480,12 +497,55 @@ func (s *Site) LanguagePrefix() string {
return "/" + prefix
}
-// Returns the identity of this site.
-// This is for internal use only.
-func (s *Site) GetIdentity() identity.Identity {
- return identity.KeyValueIdentity{Key: "site", Value: s.Lang()}
-}
-
func (s *Site) Site() page.Site {
return page.WrapSite(s)
}
+
+func (s *Site) ForEeachIdentityByName(name string, f func(identity.Identity) bool) {
+ if id, found := siteidentities.FromString(name); found {
+ if f(id) {
+ return
+ }
+ }
+}
+
+// Pages returns all pages.
+// This is for the current language only.
+func (s *Site) Pages() page.Pages {
+ return s.pageMap.getPagesInSection(
+ pageMapQueryPagesInSection{
+ pageMapQueryPagesBelowPath: pageMapQueryPagesBelowPath{
+ Path: "",
+ KeyPart: "global",
+ Include: pagePredicates.ShouldListGlobal,
+ },
+ Recursive: true,
+ IncludeSelf: true,
+ },
+ )
+}
+
+// RegularPages returns all the regular pages.
+// This is for the current language only.
+func (s *Site) RegularPages() page.Pages {
+ return s.pageMap.getPagesInSection(
+ pageMapQueryPagesInSection{
+ pageMapQueryPagesBelowPath: pageMapQueryPagesBelowPath{
+ Path: "",
+ KeyPart: "global",
+ Include: pagePredicates.ShouldListGlobal.And(pagePredicates.KindPage),
+ },
+ Recursive: true,
+ },
+ )
+}
+
+// AllPages returns all pages for all sites.
+func (s *Site) AllPages() page.Pages {
+ return s.h.Pages()
+}
+
+// AllRegularPages returns all regular pages for all sites.
+func (s *Site) AllRegularPages() page.Pages {
+ return s.h.RegularPages()
+}