Fix false path warnings with resources.PostProcess

Fixes #7735
This commit is contained in:
Bjørn Erik Pedersen 2023-06-27 09:16:42 +02:00
parent 12e4c4d5dc
commit fa0e16f4c7
4 changed files with 61 additions and 13 deletions

View file

@ -45,7 +45,6 @@ import (
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/tpl" "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"
@ -419,18 +418,6 @@ func (c *hugoBuilder) build() error {
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 { if c.r.printUnusedTemplates {
unusedTemplates := h.Tmpl().(tpl.UnusedTemplatesProvider).UnusedTemplates() unusedTemplates := h.Tmpl().(tpl.UnusedTemplatesProvider).UnusedTemplates()
for _, unusedTemplate := range unusedTemplates { for _, unusedTemplate := range unusedTemplates {

View file

@ -143,6 +143,21 @@ func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error {
if err := h.render(infol, conf); err != nil { if err := h.render(infol, conf); err != nil {
h.SendError(fmt.Errorf("render: %w", err)) h.SendError(fmt.Errorf("render: %w", err))
} }
if h.Configs.Base.LogPathWarnings {
// We need to do this before any post processing, as that may write to the same files twice
// and create false positives.
hugofs.WalkFilesystems(h.Fs.PublishDir, func(fs afero.Fs) bool {
if dfs, ok := fs.(hugofs.DuplicatesReporter); ok {
dupes := dfs.ReportDuplicates()
if dupes != "" {
h.Log.Warnln("Duplicate target paths:", dupes)
}
}
return false
})
}
if err := h.postProcess(infol); err != nil { if err := h.postProcess(infol); err != nil {
h.SendError(fmt.Errorf("postProcess: %w", err)) h.SendError(fmt.Errorf("postProcess: %w", err))
} }

View file

@ -0,0 +1,20 @@
hugo --printPathWarnings
! stdout 'Duplicate'
-- hugo.toml --
-- assets/css/styles.css --
body {
background-color: #000;
}
-- content/p1.md --
-- content/p2.md --
-- content/p3.md --
-- layouts/index.html --
Home.
-- layouts/_default/single.html --
{{ $css := resources.Get "css/styles.css" }}
{{ $css := $css | minify | fingerprint | resources.PostProcess }}
CSS: {{ $css.RelPermalink }}
{{ .Title }}

View file

@ -0,0 +1,26 @@
hugo --printPathWarnings
stdout 'Duplicate'
-- hugo.toml --
-- assets/css/styles.css --
body {
background-color: #000;
}
-- content/p1.md --
---
url: /p1/
---
-- content/p2.md --
---
url: /p1/
---
-- content/p3.md --
---
url: /p1/
---
-- layouts/index.html --
Home.
-- layouts/_default/single.html --
Single.