summaryrefslogtreecommitdiffstats
path: root/hugolib/hugo_sites.go
diff options
context:
space:
mode:
Diffstat (limited to 'hugolib/hugo_sites.go')
-rw-r--r--hugolib/hugo_sites.go26
1 files changed, 18 insertions, 8 deletions
diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go
index 4e1623b2e..a0c62f01e 100644
--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -121,6 +121,9 @@ type hugoSitesInit struct {
// Loads the data from all of the /data folders.
data *lazy.Init
+ // Performs late initialization (before render) of the templates.
+ layouts *lazy.Init
+
// Loads the Git info for all the pages if enabled.
gitInfo *lazy.Init
@@ -130,6 +133,7 @@ type hugoSitesInit struct {
func (h *hugoSitesInit) Reset() {
h.data.Reset()
+ h.layouts.Reset()
h.gitInfo.Reset()
h.translations.Reset()
}
@@ -271,6 +275,7 @@ func newHugoSites(cfg deps.DepsCfg, sites ...*Site) (*HugoSites, error) {
Sites: sites,
init: &hugoSitesInit{
data: lazy.New(),
+ layouts: lazy.New(),
gitInfo: lazy.New(),
translations: lazy.New(),
},
@@ -289,6 +294,15 @@ func newHugoSites(cfg deps.DepsCfg, sites ...*Site) (*HugoSites, error) {
return nil, nil
})
+ h.init.layouts.Add(func() (interface{}, error) {
+ for _, s := range h.Sites {
+ if err := s.Tmpl().(tpl.TemplateManager).MarkReady(); err != nil {
+ return nil, err
+ }
+ }
+ return nil, nil
+ })
+
h.init.translations.Add(func() (interface{}, error) {
if len(h.Sites) > 1 {
allTranslations := pagesToTranslationsMap(h.Sites)
@@ -429,10 +443,6 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) {
func (s *Site) withSiteTemplates(withTemplates ...func(templ tpl.TemplateManager) error) func(templ tpl.TemplateManager) error {
return func(templ tpl.TemplateManager) error {
- if err := templ.LoadTemplates(""); err != nil {
- return err
- }
-
for _, wt := range withTemplates {
if wt == nil {
continue
@@ -619,10 +629,10 @@ func (h *HugoSites) renderCrossSitesArtifacts() error {
s := h.Sites[0]
- smLayouts := []string{"sitemapindex.xml", "_default/sitemapindex.xml", "_internal/_default/sitemapindex.xml"}
+ templ := s.lookupLayouts("sitemapindex.xml", "_default/sitemapindex.xml", "_internal/_default/sitemapindex.xml")
return s.renderAndWriteXML(&s.PathSpec.ProcessingStats.Sitemaps, "sitemapindex",
- s.siteCfg.sitemap.Filename, h.toSiteInfos(), smLayouts...)
+ s.siteCfg.sitemap.Filename, h.toSiteInfos(), templ)
}
func (h *HugoSites) removePageByFilename(filename string) {
@@ -832,7 +842,7 @@ func (h *HugoSites) resetPageStateFromEvents(idset identity.Identities) {
if po.cp == nil {
continue
}
- for id, _ := range idset {
+ for id := range idset {
if po.cp.dependencyTracker.Search(id) != nil {
po.cp.Reset()
continue OUTPUTS
@@ -841,7 +851,7 @@ func (h *HugoSites) resetPageStateFromEvents(idset identity.Identities) {
}
for _, s := range p.shortcodeState.shortcodes {
- for id, _ := range idset {
+ for id := range idset {
if idm, ok := s.info.(identity.Manager); ok && idm.Search(id) != nil {
for _, po := range p.pageOutputs {
if po.cp != nil {