]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix false path warnings with resources.PostProcess
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 27 Jun 2023 07:16:42 +0000 (09:16 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 27 Jun 2023 19:55:35 +0000 (21:55 +0200)
Fixes #7735

commands/hugobuilder.go
hugolib/hugo_sites_build.go
testscripts/commands/hugo__path-warnings-postprocess.txt [new file with mode: 0644]
testscripts/commands/hugo__path-warnings.txt [new file with mode: 0644]

index 71992e409edabdd8c2d2abd2f22269ce17ab38bc..3e96bfc73d668c643d4eac28562994efd9021c16 100644 (file)
@@ -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"
@@ -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 {
index c552b9de88f49b3454a5540981de000b46e59b17..ea73c493fc5db185ab12ff1334c3e03ef5eeb367 100644 (file)
@@ -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))
                }
diff --git a/testscripts/commands/hugo__path-warnings-postprocess.txt b/testscripts/commands/hugo__path-warnings-postprocess.txt
new file mode 100644 (file)
index 0000000..0677da0
--- /dev/null
@@ -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 }}
+
diff --git a/testscripts/commands/hugo__path-warnings.txt b/testscripts/commands/hugo__path-warnings.txt
new file mode 100644 (file)
index 0000000..f7e3acd
--- /dev/null
@@ -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.
+