mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
c0d7188ec8
commit
6dec671fb9
3 changed files with 61 additions and 31 deletions
|
@ -301,33 +301,3 @@ The content.
|
|||
|
||||
b.CreateSites().Build(BuildCfg{})
|
||||
}
|
||||
|
||||
func TestBundleMany(t *testing.T) {
|
||||
|
||||
b := newTestSitesBuilder(t).WithSimpleConfigFile()
|
||||
for i := 1; i <= 50; i++ {
|
||||
b.WithContent(fmt.Sprintf("bundle%d/index.md", i), fmt.Sprintf(`
|
||||
---
|
||||
title: "Page %d"
|
||||
---
|
||||
|
||||
`, i))
|
||||
b.WithSourceFile(fmt.Sprintf("content/bundle%d/data.yaml", i), fmt.Sprintf(`
|
||||
data: v%d
|
||||
`, i))
|
||||
}
|
||||
|
||||
b.WithTemplatesAdded("_default/single.html", `
|
||||
{{ $yaml := .Resources.GetMatch "*.yaml" }}
|
||||
{{ $data := $yaml | transform.Unmarshal }}
|
||||
data content: {{ $yaml.Content | safeHTML }}
|
||||
data unmarshaled: {{ $data.data }}
|
||||
`)
|
||||
|
||||
b.CreateSites().Build(BuildCfg{})
|
||||
|
||||
for i := 1; i <= 50; i++ {
|
||||
b.AssertFileContent(fmt.Sprintf("public/bundle%d/data.yaml", i), fmt.Sprintf("data: v%d", i))
|
||||
b.AssertFileContent(fmt.Sprintf("public/bundle%d/index.html", i), fmt.Sprintf("data unmarshaled: v%d", i))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gohugoio/hugo/helpers"
|
||||
|
||||
"github.com/gohugoio/hugo/hugofs"
|
||||
|
||||
"github.com/gohugoio/hugo/common/loggers"
|
||||
|
@ -1216,3 +1218,60 @@ title: %q
|
|||
`)
|
||||
|
||||
}
|
||||
|
||||
func TestBundleTransformMany(t *testing.T) {
|
||||
|
||||
b := newTestSitesBuilder(t).WithSimpleConfigFile().Running()
|
||||
|
||||
for i := 1; i <= 50; i++ {
|
||||
b.WithContent(fmt.Sprintf("bundle%d/index.md", i), fmt.Sprintf(`
|
||||
---
|
||||
title: "Page"
|
||||
weight: %d
|
||||
---
|
||||
|
||||
`, i))
|
||||
b.WithSourceFile(fmt.Sprintf("content/bundle%d/data.yaml", i), fmt.Sprintf(`data: v%d`, i))
|
||||
|
||||
b.WithSourceFile(fmt.Sprintf("assets/data%d/data.yaml", i), fmt.Sprintf(`vdata: v%d`, i))
|
||||
|
||||
}
|
||||
|
||||
b.WithTemplatesAdded("_default/single.html", `
|
||||
{{ $bundleYaml := .Resources.GetMatch "*.yaml" }}
|
||||
{{ $assetsYaml := resources.GetMatch (printf "data%d/*.yaml" .Weight) }}
|
||||
{{ $data1 := $bundleYaml | transform.Unmarshal }}
|
||||
{{ $data2 := $assetsYaml | transform.Unmarshal }}
|
||||
{{ $bundleFingerprinted := $bundleYaml | fingerprint "md5" }}
|
||||
{{ $assetsFingerprinted := $assetsYaml | fingerprint "md5" }}
|
||||
|
||||
data content unmarshaled: {{ $data1.data }}
|
||||
data assets content unmarshaled: {{ $data2.vdata }}
|
||||
bundle fingerprinted: {{ $bundleFingerprinted.RelPermalink }}
|
||||
assets fingerprinted: {{ $assetsFingerprinted.RelPermalink }}
|
||||
`)
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
|
||||
b.Build(BuildCfg{})
|
||||
|
||||
for i := 1; i <= 50; i++ {
|
||||
b.AssertFileContent(fmt.Sprintf("public/bundle%d/data.yaml", i), fmt.Sprintf("data: v%d", i))
|
||||
b.AssertFileContent(fmt.Sprintf("public/bundle%d/index.html", i), fmt.Sprintf("data content unmarshaled: v%d", i))
|
||||
b.AssertFileContent(fmt.Sprintf("public/bundle%d/index.html", i), fmt.Sprintf("data assets content unmarshaled: v%d", i))
|
||||
|
||||
md5Asset := helpers.MD5String(fmt.Sprintf(`vdata: v%d`, i))
|
||||
b.AssertFileContent(fmt.Sprintf("public/bundle%d/index.html", i), fmt.Sprintf("assets fingerprinted: /data%d/data.%s.yaml", i, md5Asset))
|
||||
|
||||
// The original is not used, make sure it's not published.
|
||||
b.Assert(b.CheckExists(fmt.Sprintf("public/data%d/data.yaml", i)), qt.Equals, false)
|
||||
|
||||
md5Bundle := helpers.MD5String(fmt.Sprintf(`data: v%d`, i))
|
||||
b.AssertFileContent(fmt.Sprintf("public/bundle%d/index.html", i), fmt.Sprintf("bundle fingerprinted: /bundle%d/data.%s.yaml", i, md5Bundle))
|
||||
|
||||
}
|
||||
|
||||
b.EditFiles("assets/data/foo.yaml", "FOO")
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -304,7 +304,7 @@ func (r *resourceAdapter) transform(publish, setContent bool) error {
|
|||
key = key + "_" + tr.Key().Value()
|
||||
}
|
||||
|
||||
base := ResourceCacheKey(r.target.TargetPath())
|
||||
base := ResourceCacheKey(r.target.Key())
|
||||
|
||||
key = cache.cleanKey(base) + "_" + helpers.MD5String(key)
|
||||
|
||||
|
@ -537,6 +537,7 @@ type transformableResource interface {
|
|||
|
||||
resource.ContentProvider
|
||||
resource.Resource
|
||||
resource.Identifier
|
||||
}
|
||||
|
||||
type transformationUpdate struct {
|
||||
|
|
Loading…
Reference in a new issue