mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 03:12:05 -05:00
parent
ce47c21a29
commit
45d7988f2d
2 changed files with 35 additions and 10 deletions
|
@ -14,6 +14,7 @@
|
|||
package hugolib
|
||||
|
||||
import (
|
||||
"image/jpeg"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -61,8 +62,9 @@ title: "My bundle"
|
|||
{{ $b := $img2.Resize "345x678" }}
|
||||
{{ $b2 := $b.Resize "34x67" }}
|
||||
{{ $c := $img3.Resize "456x789" }}
|
||||
{{ $fingerprinted := $img1.Resize "350x" | fingerprint }}
|
||||
|
||||
{{ $images := slice $r $r2 $b $b2 $c }}
|
||||
{{ $images := slice $r $r2 $b $b2 $c $fingerprinted }}
|
||||
|
||||
{{ range $i, $r := $images }}
|
||||
{{ printf "Resized%d:" (add $i 1) }} {{ $r.Name }}|{{ $r.Width }}|{{ $r.Height }}|{{ $r.MediaType }}|{{ $r.RelPermalink }}|
|
||||
|
@ -98,20 +100,33 @@ title: "My bundle"
|
|||
b := newBuilder()
|
||||
b.Build(BuildCfg{})
|
||||
|
||||
imgExpect := []string{
|
||||
"Resized1: images/sunset.jpg|123|234|image/jpg|/images/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_123x234_resize_q75_box.jpg|",
|
||||
"Resized2: images/sunset.jpg|12|23|image/jpg|/images/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_ada4bb1a57f77a63306e3bd67286248e.jpg|",
|
||||
"Resized3: sunset.jpg|345|678|image/jpg|/mybundle/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_345x678_resize_q75_box.jpg|",
|
||||
"Resized4: sunset.jpg|34|67|image/jpg|/mybundle/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_44d8c928664d7c5a67377c6ec58425ce.jpg|",
|
||||
" Resized5: images/sunset.jpg|456|789|image/jpg|/images/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_456x789_resize_q75_box.jpg|",
|
||||
assertImage := func(width, height int, filename string) {
|
||||
filename = filepath.Join(workDir, "public", filename)
|
||||
f, err := b.Fs.Destination.Open(filename)
|
||||
c.Assert(err, qt.IsNil)
|
||||
defer f.Close()
|
||||
cfg, err := jpeg.DecodeConfig(f)
|
||||
c.Assert(cfg.Width, qt.Equals, width)
|
||||
c.Assert(cfg.Height, qt.Equals, height)
|
||||
}
|
||||
|
||||
b.AssertFileContent(filepath.Join(workDir, "public/index.html"), imgExpect...)
|
||||
imgExpect := `
|
||||
Resized1: images/sunset.jpg|123|234|image/jpg|/images/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_123x234_resize_q75_box.jpg|
|
||||
Resized2: images/sunset.jpg|12|23|image/jpg|/images/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_ada4bb1a57f77a63306e3bd67286248e.jpg|
|
||||
Resized3: sunset.jpg|345|678|image/jpg|/mybundle/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_345x678_resize_q75_box.jpg|
|
||||
Resized4: sunset.jpg|34|67|image/jpg|/mybundle/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_44d8c928664d7c5a67377c6ec58425ce.jpg|
|
||||
Resized5: images/sunset.jpg|456|789|image/jpg|/images/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_456x789_resize_q75_box.jpg|
|
||||
Resized6: images/sunset.jpg|350|219|image/jpg|/images/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_350x0_resize_q75_box.a86fe88d894e5db613f6aa8a80538fefc25b20fa24ba0d782c057adcef616f56.jpg|
|
||||
|
||||
`
|
||||
|
||||
b.AssertFileContent(filepath.Join(workDir, "public/index.html"), imgExpect)
|
||||
assertImage(350, 219, "images/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_350x0_resize_q75_box.a86fe88d894e5db613f6aa8a80538fefc25b20fa24ba0d782c057adcef616f56.jpg")
|
||||
|
||||
// Build it again to make sure we read images from file cache.
|
||||
b = newBuilder()
|
||||
b.Build(BuildCfg{})
|
||||
|
||||
b.AssertFileContent(filepath.Join(workDir, "public/index.html"), imgExpect...)
|
||||
b.AssertFileContent(filepath.Join(workDir, "public/index.html"), imgExpect)
|
||||
|
||||
}
|
||||
|
|
|
@ -174,6 +174,9 @@ func TestResourceChainBasic(t *testing.T) {
|
|||
b := newTestSitesBuilder(t)
|
||||
b.WithTemplatesAdded("index.html", `
|
||||
{{ $hello := "<h1> Hello World! </h1>" | resources.FromString "hello.html" | fingerprint "sha512" | minify | fingerprint }}
|
||||
{{ $cssFingerprinted1 := "body { background-color: lightblue; }" | resources.FromString "styles.css" | minify | fingerprint }}
|
||||
{{ $cssFingerprinted2 := "body { background-color: orange; }" | resources.FromString "styles2.css" | minify | fingerprint }}
|
||||
|
||||
|
||||
HELLO: {{ $hello.Name }}|{{ $hello.RelPermalink }}|{{ $hello.Content | safeHTML }}
|
||||
|
||||
|
@ -183,6 +186,9 @@ HELLO: {{ $hello.Name }}|{{ $hello.RelPermalink }}|{{ $hello.Content | safeHTML
|
|||
{{ $img = $img | fingerprint }}
|
||||
SUNSET: {{ $img.Name }}|{{ $img.RelPermalink }}|{{ $img.Width }}|{{ len $img.Content }}
|
||||
FIT: {{ $fit.Name }}|{{ $fit.RelPermalink }}|{{ $fit.Width }}
|
||||
CSS integrity Data first: {{ $cssFingerprinted1.Data.Integrity }} {{ $cssFingerprinted1.RelPermalink }}
|
||||
CSS integrity Data last: {{ $cssFingerprinted2.RelPermalink }} {{ $cssFingerprinted2.Data.Integrity }}
|
||||
|
||||
`)
|
||||
|
||||
fs := b.Fs.Source
|
||||
|
@ -207,9 +213,13 @@ FIT: {{ $fit.Name }}|{{ $fit.RelPermalink }}|{{ $fit.Width }}
|
|||
`
|
||||
SUNSET: images/sunset.jpg|/images/sunset.a9bf1d944e19c0f382e0d8f51de690f7d0bc8fa97390c4242a86c3e5c0737e71.jpg|900|90587
|
||||
FIT: images/sunset.jpg|/images/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_200x200_fit_q75_box.jpg|200
|
||||
|
||||
CSS integrity Data first: sha256-od9YaHw8nMOL8mUy97Sy8sKwMV3N4hI3aVmZXATxH+8= /styles.min.a1df58687c3c9cc38bf26532f7b4b2f2c2b0315dcde212376959995c04f11fef.css
|
||||
CSS integrity Data last: /styles2.min.1cfc52986836405d37f9998a63fd6dd8608e8c410e5e3db1daaa30f78bc273ba.css sha256-HPxSmGg2QF03+ZmKY/1t2GCOjEEOXj2x2qow94vCc7o=
|
||||
`)
|
||||
|
||||
b.AssertFileContent("public/styles.min.a1df58687c3c9cc38bf26532f7b4b2f2c2b0315dcde212376959995c04f11fef.css", "body{background-color:#add8e6}")
|
||||
b.AssertFileContent("public//styles2.min.1cfc52986836405d37f9998a63fd6dd8608e8c410e5e3db1daaa30f78bc273ba.css", "body{background-color:orange}")
|
||||
|
||||
b.EditFiles("page1.md", `
|
||||
---
|
||||
title: "Page 1 edit"
|
||||
|
|
Loading…
Reference in a new issue