Add --printUnusedTemplates

Fixes #9502
This commit is contained in:
Bjørn Erik Pedersen 2022-02-15 15:26:18 +01:00
parent 923419d7fd
commit f2e7b49acf
12 changed files with 167 additions and 9 deletions

View file

@ -31,6 +31,7 @@ import (
"time"
"github.com/gohugoio/hugo/hugofs/files"
"github.com/gohugoio/hugo/tpl"
"github.com/gohugoio/hugo/common/types"
@ -217,6 +218,7 @@ func initializeFlags(cmd *cobra.Command, cfg config.Provider) {
"force",
"gc",
"printI18nWarnings",
"printUnusedTemplates",
"invalidateCDN",
"layoutDir",
"logFile",
@ -501,7 +503,6 @@ func (c *commandeer) build() error {
return err
}
// TODO(bep) Feedback?
if !c.h.quiet {
fmt.Println()
c.hugo().PrintProcessingStats(os.Stdout)
@ -513,6 +514,11 @@ func (c *commandeer) build() error {
c.logger.Warnln("Duplicate target paths:", dupes)
}
}
unusedTemplates := c.hugo().Tmpl().(tpl.UnusedTemplatesProvider).UnusedTemplates()
for _, unusedTemplate := range unusedTemplates {
c.logger.Warnf("Template %s is unused, source file %s", unusedTemplate.Name(), unusedTemplate.Filename())
}
}
if c.h.buildWatch {