Repository: gohugoio/hugo (language: go)

Issue:
resources.PostProcess causes --path-warnings to falsely report duplicate content
If I have `resources.PostProcess` in my template, it falsely reports the page as duplicated with `hugo --path-warnings`.

### What version of Hugo are you using (`hugo version`)?

 v0.75.1/extended darwin/amd64 BuildDate: unknown

### Does this issue reproduce with the latest release?
Yes


Discussion / hints:
Minimal example

```bash
git clone --single-branch -b hugo-github-issue-7735 https://github.com/jmooring/hugo-testing hugo-github-issue-7735
cd hugo-github-issue-7735
npm ci
hugo --printPathWarnings
```
I'm updating a website to use TailwindCSS 3.x and following the patterns in https://github.com/bep/hugo-starter-tailwind-basic. Turns out hugo-starter-tailwind-basic relies on `resources.PostProcess` and having that in my template broke my build script, which runs `hugo` with `--printPathWarnings` and `--panicOnWarning` in the hopes of catching problems earlier.

Took me quite some time today until I was able to pin down the problem and find this issue.

Since Tailwind support seems to be something that's been worked on lately, could this issue be pinned to help others find about it earlier?

Fix patch:
diff --git a/commands/hugobuilder.go b/commands/hugobuilder.go
index 71992e409ed..3e96bfc73d6 100644
--- a/commands/hugobuilder.go
+++ b/commands/hugobuilder.go
@@ -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 {
diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go
index c552b9de88f..ea73c493fc5 100644
--- a/hugolib/hugo_sites_build.go
+++ b/hugolib/hugo_sites_build.go
@@ -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))
 		}


Test patch:
diff --git a/testscripts/commands/hugo__path-warnings-postprocess.txt b/testscripts/commands/hugo__path-warnings-postprocess.txt
new file mode 100644
index 00000000000..0677da084c5
--- /dev/null
+++ b/testscripts/commands/hugo__path-warnings-postprocess.txt
@@ -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
index 00000000000..f7e3acd952c
--- /dev/null
+++ b/testscripts/commands/hugo__path-warnings.txt
@@ -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.
+