Skip to content

Commit

Permalink
Fix --printPathWarnings when site calls templates.Defer
Browse files Browse the repository at this point in the history
This issue was introduced recently in eb7a5aa.

Fixes #13420
  • Loading branch information
bep committed Feb 19, 2025
1 parent 669216e commit c3d435a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion hugolib/hugo_sites.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ type HugoSites struct {

pageTrees *pageTrees

postRenderInit sync.Once
printUnusedTemplatesInit sync.Once
printPathWarningsInit sync.Once

// File change events with filename stored in this map will be skipped.
skipRebuildForFilenamesMu sync.Mutex
Expand Down
23 changes: 18 additions & 5 deletions hugolib/hugo_sites_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,18 @@ func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error {
return err
}

// We need to do this before render deferred.
if err := h.printPathWarningsOnce(); err != nil {
h.SendError(fmt.Errorf("printPathWarnings: %w", err))
}

if err := h.renderDeferred(infol); err != nil {
h.SendError(fmt.Errorf("renderDeferred: %w", err))
}

if err := h.postRenderOnce(); err != nil {
h.SendError(fmt.Errorf("postRenderOnce: %w", err))
// This needs to be done after the deferred rendering to get complete template usage coverage.
if err := h.printUnusedTemplatesOnce(); err != nil {
h.SendError(fmt.Errorf("printPathWarnings: %w", err))
}

if err := h.postProcess(infol); err != nil {
Expand Down Expand Up @@ -545,9 +551,9 @@ func (s *Site) executeDeferredTemplates(de *deps.DeferredExecutions) error {
return g.Wait()
}

// / postRenderOnce runs some post processing that only needs to be done once, e.g. printing of unused templates.
func (h *HugoSites) postRenderOnce() error {
h.postRenderInit.Do(func() {
// printPathWarningsOnce prints path warnings if enabled.
func (h *HugoSites) printPathWarningsOnce() error {
h.printPathWarningsInit.Do(func() {
conf := h.Configs.Base
if conf.PrintPathWarnings {
// We need to do this before any post processing, as that may write to the same files twice
Expand All @@ -562,7 +568,14 @@ func (h *HugoSites) postRenderOnce() error {
return false
})
}
})
return nil
}

// / printUnusedTemplatesOnce prints unused templates if enabled.
func (h *HugoSites) printUnusedTemplatesOnce() error {
h.printUnusedTemplatesInit.Do(func() {
conf := h.Configs.Base
if conf.PrintUnusedTemplates {
unusedTemplates := h.Tmpl().(tpl.UnusedTemplatesProvider).UnusedTemplates()
for _, unusedTemplate := range unusedTemplates {
Expand Down

0 comments on commit c3d435a

Please sign in to comment.