Skip to content

Commit

Permalink
Fix false path warnings with resources.PostProcess
Browse files Browse the repository at this point in the history
Fixes #7735
  • Loading branch information
bep committed Jun 27, 2023
1 parent 12e4c4d commit fa0e16f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 13 deletions.
13 changes: 0 additions & 13 deletions commands/hugobuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import (
"github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/tpl"
"github.com/gohugoio/hugo/watcher"
"github.com/spf13/afero"
"github.com/spf13/fsync"
"golang.org/x/sync/errgroup"
"golang.org/x/sync/semaphore"
Expand Down Expand Up @@ -419,18 +418,6 @@ func (c *hugoBuilder) build() error {
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 {
Expand Down
15 changes: 15 additions & 0 deletions hugolib/hugo_sites_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,21 @@ func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error {
if err := h.render(infol, conf); err != nil {
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 {
h.SendError(fmt.Errorf("postProcess: %w", err))
}
Expand Down
20 changes: 20 additions & 0 deletions testscripts/commands/hugo__path-warnings-postprocess.txt
Original file line number Diff line number Diff line change
@@ -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 }}

26 changes: 26 additions & 0 deletions testscripts/commands/hugo__path-warnings.txt
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit fa0e16f

Please sign in to comment.