@@ -176,12 +176,18 @@ func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error {
176176 return err
177177 }
178178
179+ // We need to do this before render deferred.
180+ if err := h .printPathWarningsOnce (); err != nil {
181+ h .SendError (fmt .Errorf ("printPathWarnings: %w" , err ))
182+ }
183+
179184 if err := h .renderDeferred (infol ); err != nil {
180185 h .SendError (fmt .Errorf ("renderDeferred: %w" , err ))
181186 }
182187
183- if err := h .postRenderOnce (); err != nil {
184- h .SendError (fmt .Errorf ("postRenderOnce: %w" , err ))
188+ // This needs to be done after the deferred rendering to get complete template usage coverage.
189+ if err := h .printUnusedTemplatesOnce (); err != nil {
190+ h .SendError (fmt .Errorf ("printPathWarnings: %w" , err ))
185191 }
186192
187193 if err := h .postProcess (infol ); err != nil {
@@ -545,9 +551,9 @@ func (s *Site) executeDeferredTemplates(de *deps.DeferredExecutions) error {
545551 return g .Wait ()
546552}
547553
548- // / postRenderOnce runs some post processing that only needs to be done once, e.g. printing of unused templates .
549- func (h * HugoSites ) postRenderOnce () error {
550- h .postRenderInit .Do (func () {
554+ // printPathWarningsOnce prints path warnings if enabled .
555+ func (h * HugoSites ) printPathWarningsOnce () error {
556+ h .printPathWarningsInit .Do (func () {
551557 conf := h .Configs .Base
552558 if conf .PrintPathWarnings {
553559 // We need to do this before any post processing, as that may write to the same files twice
@@ -562,7 +568,14 @@ func (h *HugoSites) postRenderOnce() error {
562568 return false
563569 })
564570 }
571+ })
572+ return nil
573+ }
565574
575+ // / printUnusedTemplatesOnce prints unused templates if enabled.
576+ func (h * HugoSites ) printUnusedTemplatesOnce () error {
577+ h .printUnusedTemplatesInit .Do (func () {
578+ conf := h .Configs .Base
566579 if conf .PrintUnusedTemplates {
567580 unusedTemplates := h .Tmpl ().(tpl.UnusedTemplatesProvider ).UnusedTemplates ()
568581 for _ , unusedTemplate := range unusedTemplates {
0 commit comments