Skip to content

Commit d19e0a4

Browse files
committed
resources/images: Bump formatVersionNumbers.PNG and fix version cache busting for images.Filter (note)
So, sites converting to PNG sees the fixes referenced without flushing the image cache. See #12536 See #12543 Closes #15266
1 parent 9171dae commit d19e0a4

10 files changed

Lines changed: 62 additions & 40 deletions

File tree

‎hugolib/hugo_sites_multihost_test.go‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,13 @@ title: "Mybundle fr"
154154
`
155155
b := Test(t, files)
156156

157-
b.AssertFileContent("public/fr/section/mybundle/index.html",
157+
b.AssertFileContent(
158+
"public/fr/section/mybundle/index.html",
158159
"fr: .body{color:french}|/section/mybundle/styles.min.css|",
159160
)
160161

161-
b.AssertFileContent("public/en/section/mybundle/index.html",
162+
b.AssertFileContent(
163+
"public/en/section/mybundle/index.html",
162164
"en: .body{color:english}|/section/mybundle/styles.min.css|",
163165
)
164166

@@ -207,9 +209,9 @@ title: mybundle-en
207209
b.AssertFileExists("public/de/mybundle/pixel.png", true)
208210
b.AssertFileExists("public/en/mybundle/pixel.png", true)
209211

210-
b.AssertFileExists("public/de/mybundle/pixel_hu_c8522c65d73a0421.png", true)
212+
b.AssertFileExists("public/de/mybundle/pixel_hu_a25c5b589ae00856.png", true)
211213
// failing test below
212-
b.AssertFileExists("public/en/mybundle/pixel_hu_c8522c65d73a0421.png", true)
214+
b.AssertFileExists("public/en/mybundle/pixel_hu_a25c5b589ae00856.png", true)
213215
}
214216

215217
func TestMultihostResourceOneBaseURLWithSubPath(t *testing.T) {

‎hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ docs/p1/sub/mymixcasetext2.txt
112112
// Page from markdown file.
113113
b.AssertFileContent("public/docs/pfile/index.html", "Dates: Date: 2023-03-01|Lastmod: 2023-03-01|PublishDate: 2023-03-01|ExpiryDate: 0001-01-01|")
114114
// Pages from gotmpl.
115-
b.AssertFileContent("public/docs/p1/index.html",
115+
b.AssertFileContent(
116+
"public/docs/p1/index.html",
116117
"Single: p1:p1|",
117118
"Path: /docs/p1|",
118119
"<strong>Hello World</strong>",
@@ -125,7 +126,7 @@ docs/p1/sub/mymixcasetext2.txt
125126
"RelPermalink: /docs/p1/sub/mymixcasetext2.txt|Name: sub/mymixcasetext2.txt|",
126127
"RelPermalink: /mydata.yaml|Name: sub/data1.yaml|Title: Sub data|Params: map[]|",
127128
"Featured Image: /a/pixel.png|featured.png|",
128-
"Resized Featured Image: /a/pixel_hu_a354833fd576551d.png|10|",
129+
"Resized Featured Image: /a/pixel_hu_51638841a22bb583.png|10|",
129130
// Resource from string
130131
"RelPermalink: /docs/p1/mytext.txt|Name: textresource|Title: My Text Resource|Params: map[param1:param1v]|",
131132
// Dates
@@ -174,25 +175,29 @@ allow = [%s]
174175
b := hugolib.Test(t, files)
175176

176177
if supportsAsciiDoc {
177-
b.AssertFileContent("public/docs/asciidoc/index.html",
178+
b.AssertFileContent(
179+
"public/docs/asciidoc/index.html",
178180
"Mark my words, <mark>automation is essential</mark>",
179181
"Path: /docs/asciidoc|",
180182
)
181183
}
182184
if supportsPandoc {
183-
b.AssertFileContent("public/docs/pandoc/index.html",
185+
b.AssertFileContent(
186+
"public/docs/pandoc/index.html",
184187
"This <del>is deleted text.</del>",
185188
"Path: /docs/pandoc|",
186189
)
187190
}
188191
if supportsRst {
189-
b.AssertFileContent("public/docs/rst/index.html",
192+
b.AssertFileContent(
193+
"public/docs/rst/index.html",
190194
"This is <em>bold</em>",
191195
"Path: /docs/rst|",
192196
)
193197
}
194198

195-
b.AssertFileContent("public/docs/org/index.html",
199+
b.AssertFileContent(
200+
"public/docs/org/index.html",
196201
"the ability to use <del>strikethrough</del> is a plus",
197202
"Path: /docs/org|",
198203
)
@@ -305,14 +310,16 @@ func TestPagesFromGoTmplMovePage(t *testing.T) {
305310
func TestPagesFromGoTmplRemoveGoTmpl(t *testing.T) {
306311
t.Parallel()
307312
b := hugolib.TestRunning(t, filesPagesFromDataTempleBasic)
308-
b.AssertFileContent("public/index.html",
313+
b.AssertFileContent(
314+
"public/index.html",
309315
"RegularPagesRecursive: p1:p1:/docs/p1|p2title:/docs/p2|p3title:/docs/p3|p4title:/docs/p4|pfile:/docs/pfile|$",
310316
"Sections: Docs:/docs|",
311317
)
312318
b.AssertFileContent("public/docs/index.html", "RegularPagesRecursive: p1:p1:/docs/p1|p2title:/docs/p2|p3title:/docs/p3|p4title:/docs/p4|pfile:/docs/pfile|$")
313319
b.RemoveFiles("content/docs/_content.gotmpl").Build()
314320
// One regular page left.
315-
b.AssertFileContent("public/index.html",
321+
b.AssertFileContent(
322+
"public/index.html",
316323
"RegularPagesRecursive: pfile:/docs/pfile|$",
317324
"Sections: Docs:/docs|",
318325
)
@@ -596,7 +603,8 @@ disableKinds = ['home','section','rss','sitemap','taxonomy','term']
596603

597604
b := hugolib.Test(t, files)
598605

599-
b.AssertFileContent("public/p1/index.html",
606+
b.AssertFileContent(
607+
"public/p1/index.html",
600608
"p1|param1v",
601609
"data1.yaml|param1v",
602610
)
@@ -651,7 +659,8 @@ Footer: {{ range index site.Menus.footer }}{{ .Name }}|{{ end }}|
651659
`
652660
b := hugolib.Test(t, files)
653661

654-
b.AssertFileContent("public/index.html",
662+
b.AssertFileContent(
663+
"public/index.html",
655664
"Main: Main|p1|p2||",
656665
"Footer: Footer|p2||",
657666
)
@@ -706,7 +715,8 @@ summary: {{ .Summary }}|content: {{ .Content}}
706715

707716
b := hugolib.Test(t, files)
708717

709-
b.AssertFileContent("public/s1/p1/index.html",
718+
b.AssertFileContent(
719+
"public/s1/p1/index.html",
710720
"<p>aaa</p>|content: <p>aaa</p>\n<p>bbb</p>",
711721
)
712722
}

‎resources/image.go‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,14 @@ func (i *imageResource) Filter(filters ...any) (images.ImageResource, error) {
322322
}
323323

324324
confMain.Action = images.ActionFilter
325-
confMain.Key = hashing.HashString(gfilters)
325+
opts := []any{gfilters}
326+
if images.MainImageVersionNumber > 0 {
327+
opts = append(opts, images.MainImageVersionNumber)
328+
}
329+
if v := images.FormatVersionNumbers[confMain.TargetFormat]; v > 0 {
330+
opts = append(opts, v)
331+
}
332+
confMain.Key = hashing.HashString(opts...)
326333

327334
// Geometric filters cannot introduce colors outside the source palette.
328335
for _, f := range gfilters {

‎resources/image_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func TestImageTransformFormat(t *testing.T) {
216216

217217
imagePng, err := image.Resize("450x png")
218218
c.Assert(err, qt.IsNil)
219-
c.Assert(imagePng.RelPermalink(), qt.Equals, "/a/sunset_hu_63ccccb11ff4e285.png")
219+
c.Assert(imagePng.RelPermalink(), qt.Equals, "/a/sunset_hu_ae7e4a663628f945.png")
220220
c.Assert(imagePng.ResourceType(), qt.Equals, "image")
221221
assertExtWidthHeight(imagePng, ".png", 450, 281)
222222
c.Assert(imagePng.Name(), qt.Equals, "sunset.jpg")
@@ -391,7 +391,7 @@ func TestImageResize8BitPNG(t *testing.T) {
391391
resized, err := image.Resize("800x")
392392
c.Assert(err, qt.IsNil)
393393
c.Assert(resized.MediaType().Type, qt.Equals, "image/png")
394-
c.Assert(resized.RelPermalink(), qt.Equals, "/a/gohugoio_hu_626cfc4db4222bfe.png")
394+
c.Assert(resized.RelPermalink(), qt.Equals, "/a/gohugoio_hu_3ddd57bfb01f7376.png")
395395
c.Assert(resized.Width(), qt.Equals, 800)
396396
}
397397

‎resources/images/config.go‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,14 @@ var (
8484

8585
// Increment to mark all processed images as stale. Only use when absolutely needed.
8686
// See the finer grained smartCropVersionNumber.
87-
mainImageVersionNumber = 1
87+
MainImageVersionNumber = 1
8888

8989
// Increment a format's version number to mark all processed images targeting
9090
// that format as stale, e.g. after a change to its encoder. This is finer
9191
// grained than mainImageVersionNumber, which invalidates every format.
92-
formatVersionNumbers = map[Format]int{
92+
FormatVersionNumbers = map[Format]int{
9393
AVIF: 1,
94+
PNG: 1, // See issue 12543, 12536
9495
}
9596
)
9697

@@ -335,11 +336,11 @@ func DecodeImageConfig(options []string, defaults *config.ConfigNamespace[Imagin
335336
return c, err
336337
}
337338

338-
if mainImageVersionNumber > 0 {
339-
options = append(options, strconv.Itoa(mainImageVersionNumber))
339+
if MainImageVersionNumber > 0 {
340+
options = append(options, strconv.Itoa(MainImageVersionNumber))
340341
}
341342

342-
if v := formatVersionNumbers[c.TargetFormat]; v > 0 {
343+
if v := FormatVersionNumbers[c.TargetFormat]; v > 0 {
343344
options = append(options, "tfv"+strconv.Itoa(v))
344345
}
345346

‎resources/resources_integration_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ resize 2|RelPermalink: {{ $image.RelPermalink }}|MediaType: {{ $image.MediaType
143143
b := hugolib.Test(t, files)
144144

145145
b.AssertFileContent("public/index.html",
146-
"jpg|RelPermalink: /images/pixel_hu_38c3f257174fc757.jpg|MediaType: image/jpeg|Width: 1|Height: 1|",
147-
"resize 1|RelPermalink: /images/pixel_hu_b5c2a3d88991f65a.jpg|MediaType: image/jpeg|Width: 20|Height: 30|",
148-
"resize 2|RelPermalink: /images/pixel_hu_b5c2a3d88991f65a.jpg|MediaType: image/jpeg|Width: 20|Height: 30|",
146+
"jpg|RelPermalink: /images/pixel_hu_43e529ee1951bebf.jpg|MediaType: image/jpeg|Width: 1|Height: 1|",
147+
"resize 1|RelPermalink: /images/pixel_hu_81fc53effe4c3cf6.jpg|MediaType: image/jpeg|Width: 20|Height: 30|",
148+
"resize 2|RelPermalink: /images/pixel_hu_81fc53effe4c3cf6.jpg|MediaType: image/jpeg|Width: 20|Height: 30|",
149149
)
150150
}
151151

‎resources/transform_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,15 +386,15 @@ func TestTransform(t *testing.T) {
386386
resizedPublished1, err := img.Resize("40x40")
387387
c.Assert(err, qt.IsNil)
388388
c.Assert(resizedPublished1.Height(), qt.Equals, 40)
389-
c.Assert(resizedPublished1.RelPermalink(), qt.Equals, "/gopher.changed_hu_6347c67500afc377.png")
390-
assertShouldExist(c, spec, "public/gopher.changed_hu_6347c67500afc377.png", true)
389+
c.Assert(resizedPublished1.RelPermalink(), qt.Equals, "/gopher.changed_hu_dbaf8010a3fe3487.png")
390+
assertShouldExist(c, spec, "public/gopher.changed_hu_dbaf8010a3fe3487.png", true)
391391

392392
// Permalink called.
393393
resizedPublished2, err := img.Resize("30x30")
394394
c.Assert(err, qt.IsNil)
395395
c.Assert(resizedPublished2.Height(), qt.Equals, 30)
396-
c.Assert(resizedPublished2.Permalink(), qt.Equals, "https://example.com/gopher.changed_hu_2d293650135f63d6.png")
397-
assertShouldExist(c, spec, "public/gopher.changed_hu_2d293650135f63d6.png", true)
396+
c.Assert(resizedPublished2.Permalink(), qt.Equals, "https://example.com/gopher.changed_hu_83657b4754113fc4.png")
397+
assertShouldExist(c, spec, "public/gopher.changed_hu_83657b4754113fc4.png", true)
398398

399399
assertNoDuplicateWrites(c, spec)
400400
})

‎testscripts/commands/hugo_gc_mixed_case_cache_dir.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ hugo
1111

1212
stdout 'Processed images │ 1 '
1313
tree resources/_gen
14-
stdout 'pix_hu_a354833fd576551d.png'
14+
stdout 'pix_hu_51638841a22bb583.png'
1515

1616
# Simulate a cache created by an older Hugo version.
1717
mv resources/_gen/images/mybundle resources/_gen/images/MyBundle
@@ -20,7 +20,7 @@ hugo --gc
2020
stdout 'Cleaned │ 0 '
2121

2222
tree resources/_gen
23-
stdout 'pix_hu_a354833fd576551d.png'
23+
stdout 'pix_hu_51638841a22bb583.png'
2424

2525
-- hugo.toml --
2626
disableKinds = ["term", "taxonomy", "home"]

‎tpl/images/images_integration_test.go‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ disableKinds = ['page','rss','section','sitemap','taxonomy','term']
7979
`
8080

8181
b := hugolib.Test(t, files)
82-
b.AssertFileContent("public/index.html",
82+
b.AssertFileContent(
83+
"public/index.html",
8384
`<img data-id="0" data-img-hash="6ccacf8056c41475" data-level="" data-scale="" data-targetDir="" src="/qr_924bf7d80a564b23.png">`,
8485
`<img data-id="1" data-img-hash="6ccacf8056c41475" data-level="medium" data-scale="" data-targetDir="" src="/qr_924bf7d80a564b23.png">`,
8586
`<img data-id="2" data-img-hash="6ccacf8056c41475" data-level="medium" data-scale="4" data-targetDir="" src="/qr_924bf7d80a564b23.png">`,
@@ -161,8 +162,8 @@ Brightnes func: {{ ($img | images.Filter (images.Brightness 12) ).RelPermalink }
161162
b.AssertFileContent("public/index.html", `
162163
images.Config: 222
163164
Resize to 100x100: 100
164-
Brightnes method: /qr_hu_d5f06fd7594d0594.png
165-
Brightnes func: /qr_hu_d5f06fd7594d0594.png
165+
Brightnes method: /qr_hu_e82a6802e23c740e.png
166+
Brightnes func: /qr_hu_e82a6802e23c740e.png
166167
`)
167168
}
168169

@@ -184,8 +185,8 @@ Brightnes func: {{ ($img | images.Filter (images.Brightness 12) ).RelPermalink }
184185
b.AssertFileContent("public/index.html", `
185186
images.Config: 222
186187
Resize to 100x100: 100
187-
Brightnes method: /qr_hu_d5f06fd7594d0594.webp
188-
Brightnes func: /qr_hu_d5f06fd7594d0594.webp
188+
Brightnes method: /qr_hu_61e637d0f762ec78.webp
189+
Brightnes func: /qr_hu_61e637d0f762ec78.webp
189190
`)
190191
}
191192

@@ -214,7 +215,7 @@ Image: {{ $img.RelPermalink }}
214215
cfg.NeedsOsFS = true
215216
cfg.WorkingDir = tempDir
216217
}))
217-
b.AssertFileContent("public/index.html", `Image: /qr_hu_6b5f59be9c4d3b3a.webp`)
218+
b.AssertFileContent("public/index.html", `Image: /qr_hu_7178b50f0d0a9def.webp`)
218219

219220
}
220221
}

‎tpl/resources/resources_integration_test.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Copy3: {{ $copy3.RelPermalink}}|{{ $copy3.MediaType }}|{{ $copy3.Content | safeJ
6060

6161
b.AssertFileContent("public/index.html", `
6262
Image Orig: /blog/images/pixel.png|image/png|1|1|
63-
Image Copy1: /blog/images/copy_hu_ef85c36d9b9eff0.png|image/png|3|4|
63+
Image Copy1: /blog/images/copy_hu_e592d810de530dee.png|image/png|3|4|
6464
Image Copy2: /blog/images/copy2.png|image/png|3|4|
6565
Image Copy3: image/png|3|4|
6666
Orig: /blog/js/foo.js|text/javascript|let foo;|
@@ -271,7 +271,8 @@ disableKinds = ['page','section','rss','sitemap','taxonomy','term']
271271

272272
b := hugolib.Test(t, files, hugolib.TestOptWarn())
273273

274-
b.AssertFileContent("public/index.html",
274+
b.AssertFileContent(
275+
"public/index.html",
275276
".dartsass{color:red}",
276277
".libsass{color:blue}",
277278
)

0 commit comments

Comments
 (0)