mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 00:12:11 -05:00
Re-add --printUnusedTemplates and --printPathWarnings
And now with tests. Updates #10953
This commit is contained in:
parent
e4e0313c80
commit
d6197a41fa
4 changed files with 59 additions and 7 deletions
|
@ -115,11 +115,13 @@ type rootCommand struct {
|
||||||
environment string
|
environment string
|
||||||
|
|
||||||
// Common build flags.
|
// Common build flags.
|
||||||
baseURL string
|
baseURL string
|
||||||
gc bool
|
gc bool
|
||||||
poll string
|
poll string
|
||||||
panicOnWarning bool
|
panicOnWarning bool
|
||||||
forceSyncStatic bool
|
forceSyncStatic bool
|
||||||
|
printPathWarnings bool
|
||||||
|
printUnusedTemplates bool
|
||||||
|
|
||||||
// Profile flags (for debugging of performance problems)
|
// Profile flags (for debugging of performance problems)
|
||||||
cpuprofile string
|
cpuprofile string
|
||||||
|
@ -538,8 +540,8 @@ func applyLocalBuildFlags(cmd *cobra.Command, r *rootCommand) {
|
||||||
cmd.Flags().BoolP("noChmod", "", false, "don't sync permission mode of files")
|
cmd.Flags().BoolP("noChmod", "", false, "don't sync permission mode of files")
|
||||||
cmd.Flags().BoolP("noBuildLock", "", false, "don't create .hugo_build.lock file")
|
cmd.Flags().BoolP("noBuildLock", "", false, "don't create .hugo_build.lock file")
|
||||||
cmd.Flags().BoolP("printI18nWarnings", "", false, "print missing translations")
|
cmd.Flags().BoolP("printI18nWarnings", "", false, "print missing translations")
|
||||||
cmd.Flags().BoolP("printPathWarnings", "", false, "print warnings on duplicate target paths etc.")
|
cmd.Flags().BoolVarP(&r.printPathWarnings, "printPathWarnings", "", false, "print warnings on duplicate target paths etc.")
|
||||||
cmd.Flags().BoolP("printUnusedTemplates", "", false, "print warnings on unused templates.")
|
cmd.Flags().BoolVarP(&r.printUnusedTemplates, "printUnusedTemplates", "", false, "print warnings on unused templates.")
|
||||||
cmd.Flags().StringVarP(&r.cpuprofile, "profile-cpu", "", "", "write cpu profile to `file`")
|
cmd.Flags().StringVarP(&r.cpuprofile, "profile-cpu", "", "", "write cpu profile to `file`")
|
||||||
cmd.Flags().StringVarP(&r.memprofile, "profile-mem", "", "", "write memory profile to `file`")
|
cmd.Flags().StringVarP(&r.memprofile, "profile-mem", "", "", "write memory profile to `file`")
|
||||||
cmd.Flags().BoolVarP(&r.printm, "printMemoryUsage", "", false, "print memory usage to screen at intervals")
|
cmd.Flags().BoolVarP(&r.printm, "printMemoryUsage", "", false, "print memory usage to screen at intervals")
|
||||||
|
|
|
@ -41,7 +41,9 @@ import (
|
||||||
"github.com/gohugoio/hugo/hugolib/filesystems"
|
"github.com/gohugoio/hugo/hugolib/filesystems"
|
||||||
"github.com/gohugoio/hugo/livereload"
|
"github.com/gohugoio/hugo/livereload"
|
||||||
"github.com/gohugoio/hugo/resources/page"
|
"github.com/gohugoio/hugo/resources/page"
|
||||||
|
"github.com/gohugoio/hugo/tpl"
|
||||||
"github.com/gohugoio/hugo/watcher"
|
"github.com/gohugoio/hugo/watcher"
|
||||||
|
"github.com/spf13/afero"
|
||||||
"github.com/spf13/fsync"
|
"github.com/spf13/fsync"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
"golang.org/x/sync/semaphore"
|
"golang.org/x/sync/semaphore"
|
||||||
|
@ -411,6 +413,26 @@ func (c *hugoBuilder) build() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.r.printPathWarnings {
|
||||||
|
hugofs.WalkFilesystems(h.Fs.PublishDir, func(fs afero.Fs) bool {
|
||||||
|
if dfs, ok := fs.(hugofs.DuplicatesReporter); ok {
|
||||||
|
dupes := dfs.ReportDuplicates()
|
||||||
|
if dupes != "" {
|
||||||
|
c.r.logger.Warnln("Duplicate target paths:", dupes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.r.printUnusedTemplates {
|
||||||
|
unusedTemplates := h.Tmpl().(tpl.UnusedTemplatesProvider).UnusedTemplates()
|
||||||
|
for _, unusedTemplate := range unusedTemplates {
|
||||||
|
c.r.logger.Warnf("Template %s is unused, source file %s", unusedTemplate.Name(), unusedTemplate.Filename())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
h.PrintProcessingStats(os.Stdout)
|
h.PrintProcessingStats(os.Stdout)
|
||||||
c.r.Println()
|
c.r.Println()
|
||||||
}
|
}
|
||||||
|
|
17
testscripts/commands/hugo_printpathwarnings.txt
Normal file
17
testscripts/commands/hugo_printpathwarnings.txt
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
hugo --printPathWarnings
|
||||||
|
|
||||||
|
stdout 'Duplicate target paths: .index.html \(2\)'
|
||||||
|
|
||||||
|
-- hugo.toml --
|
||||||
|
disableKinds = ["taxonomy", "term", "RSS", "sitemap", "robotsTXT", "404", "section"]
|
||||||
|
baseURL = "https://example.org/"
|
||||||
|
-- layouts/_default/single.html --
|
||||||
|
Single.
|
||||||
|
-- layouts/index.html --
|
||||||
|
Home.
|
||||||
|
-- content/p1.md --
|
||||||
|
---
|
||||||
|
title: "P1"
|
||||||
|
url: "/"
|
||||||
|
---
|
||||||
|
|
11
testscripts/commands/hugo_printunusedtemplates.txt
Normal file
11
testscripts/commands/hugo_printunusedtemplates.txt
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
hugo --printUnusedTemplates
|
||||||
|
|
||||||
|
stdout 'Template _default/list.html is unused'
|
||||||
|
|
||||||
|
-- hugo.toml --
|
||||||
|
disableKinds = ["taxonomy", "term", "RSS", "sitemap", "robotsTXT", "404", "section", "page"]
|
||||||
|
baseURL = "https://example.org/"
|
||||||
|
-- layouts/index.html --
|
||||||
|
Home.
|
||||||
|
-- layouts/_default/list.html --
|
||||||
|
{{ errorf "unused template: %s" .Kind }}
|
Loading…
Reference in a new issue