summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-02-15 15:26:18 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-02-15 20:01:57 +0100
commitf2e7b49acfaeab4e1a28cb1096f6461b555900fa (patch)
tree1dbcdfe580801a81f978ee0b5dd7b89523da2b9c /commands
parent923419d7fde2056f47668acb0981135bce543b7e (diff)
Add --printUnusedTemplates
Fixes #9502
Diffstat (limited to 'commands')
-rw-r--r--commands/commands.go1
-rw-r--r--commands/commands_test.go1
-rw-r--r--commands/hugo.go8
3 files changed, 9 insertions, 1 deletions
diff --git a/commands/commands.go b/commands/commands.go
index 63707e368..10b7a6649 100644
--- a/commands/commands.go
+++ b/commands/commands.go
@@ -306,6 +306,7 @@ func (cc *hugoBuilderCommon) handleFlags(cmd *cobra.Command) {
cmd.Flags().BoolP("noChmod", "", false, "don't sync permission mode of files")
cmd.Flags().BoolP("printI18nWarnings", "", false, "print missing translations")
cmd.Flags().BoolP("printPathWarnings", "", false, "print warnings on duplicate target paths etc.")
+ cmd.Flags().BoolP("printUnusedTemplates", "", false, "print warnings on unused templates.")
cmd.Flags().StringVarP(&cc.cpuprofile, "profile-cpu", "", "", "write cpu profile to `file`")
cmd.Flags().StringVarP(&cc.memprofile, "profile-mem", "", "", "write memory profile to `file`")
cmd.Flags().BoolVarP(&cc.printm, "printMemoryUsage", "", false, "print memory usage to screen at intervals")
diff --git a/commands/commands_test.go b/commands/commands_test.go
index 9e623e9a2..b4fb89621 100644
--- a/commands/commands_test.go
+++ b/commands/commands_test.go
@@ -197,6 +197,7 @@ func TestFlags(t *testing.T) {
"--renderToDisk",
"--source=mysource",
"--printPathWarnings",
+ "--printUnusedTemplates",
},
check: func(c *qt.C, sc *serverCmd) {
c.Assert(sc, qt.Not(qt.IsNil))
diff --git a/commands/hugo.go b/commands/hugo.go
index ce3c4ab7b..8c5294f00 100644
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -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 {