Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix --printPathWarnings when site calls templates.Defer #13421

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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