summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-09-14 11:58:45 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-09-14 19:09:20 +0200
commit74daca6b3050d96cd3a08b13f45de24edb450163 (patch)
treed740f7e7174c4685dae8cb262a790300b005be76 /hugolib
parent1fd4c562afd467f246c632e9f3fed0a1f350d8dc (diff)
Support PostProcess for all file types
Not just HTML. Fixes #10269
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/hugo_sites_build.go19
-rw-r--r--hugolib/resource_chain_test.go10
-rw-r--r--hugolib/testhelpers_test.go8
3 files changed, 21 insertions, 16 deletions
diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go
index 1a191257c..3bebc5284 100644
--- a/hugolib/hugo_sites_build.go
+++ b/hugolib/hugo_sites_build.go
@@ -18,7 +18,6 @@ import (
"context"
"encoding/json"
"fmt"
- "os"
"path/filepath"
"runtime/trace"
"strings"
@@ -439,23 +438,15 @@ func (h *HugoSites) postProcess() error {
return nil
}
- _ = afero.Walk(h.BaseFs.PublishFs, "", func(path string, info os.FileInfo, err error) error {
- if info == nil || info.IsDir() {
- return nil
- }
-
- if !strings.HasSuffix(path, "html") {
- return nil
- }
-
+ for _, filename := range h.Deps.FilenameHasPostProcessPrefix {
+ filename := filename
g.Run(func() error {
- return handleFile(path)
+ return handleFile(filename)
})
-
- return nil
- })
+ }
// Prepare for a new build.
+ h.Deps.FilenameHasPostProcessPrefix = nil
for _, s := range h.Sites {
s.ResourceSpec.PostProcessResources = make(map[string]postpub.PostPublishedResource)
}
diff --git a/hugolib/resource_chain_test.go b/hugolib/resource_chain_test.go
index d94d389a7..4edc2cb31 100644
--- a/hugolib/resource_chain_test.go
+++ b/hugolib/resource_chain_test.go
@@ -168,6 +168,11 @@ HELLO: {{ $hello.RelPermalink }}
HELLO: {{ $hello.RelPermalink }}|Integrity: {{ $hello.Data.Integrity }}|MediaType: {{ $hello.MediaType.Type }}
HELLO2: Name: {{ $hello.Name }}|Content: {{ $hello.Content }}|Title: {{ $hello.Title }}|ResourceType: {{ $hello.ResourceType }}
+// Issue #10269
+{{ $m := dict "relPermalink" $hello.RelPermalink "integrity" $hello.Data.Integrity "mediaType" $hello.MediaType.Type }}
+{{ $json := jsonify (dict "indent" " ") $m | resources.FromString "hello.json" -}}
+JSON: {{ $json.RelPermalink }}
+
// Issue #8884
<a href="hugo.rocks">foo</a>
<a href="{{ $hello.RelPermalink }}" integrity="{{ $hello.Data.Integrity}}">Hello</a>
@@ -188,6 +193,11 @@ End.`)
b.AssertFileContent("public/page1/index.html", `HELLO: /hello.min.a2d1cb24f24b322a7dad520414c523e9.html`)
b.AssertFileContent("public/page2/index.html", `HELLO: /hello.min.a2d1cb24f24b322a7dad520414c523e9.html`)
+ b.AssertFileContent("public/hello.json", `
+integrity": "md5-otHLJPJLMip9rVIEFMUj6Q==
+mediaType": "text/html
+relPermalink": "/hello.min.a2d1cb24f24b322a7dad520414c523e9.html"
+`)
}
func BenchmarkResourceChainPostProcess(b *testing.B) {
diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go
index 46fa35deb..ca74e9340 100644
--- a/hugolib/testhelpers_test.go
+++ b/hugolib/testhelpers_test.go
@@ -764,8 +764,12 @@ func (s *sitesBuilder) AssertImage(width, height int, filename string) {
func (s *sitesBuilder) AssertNoDuplicateWrites() {
s.Helper()
- d := s.Fs.PublishDir.(hugofs.DuplicatesReporter)
- s.Assert(d.ReportDuplicates(), qt.Equals, "")
+ hugofs.WalkFilesystems(s.Fs.PublishDir, func(fs afero.Fs) bool {
+ if dfs, ok := fs.(hugofs.DuplicatesReporter); ok {
+ s.Assert(dfs.ReportDuplicates(), qt.Equals, "")
+ }
+ return false
+ })
}
func (s *sitesBuilder) FileContent(filename string) string {