Fix cache keys for bundled resoures in transform.Unmarshal
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 12 Sep 2019 17:53:31 +0000 (19:53 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 12 Sep 2019 18:58:06 +0000 (20:58 +0200)
Fixes #6327

hugolib/hugo_smoke_test.go
resources/resource.go
resources/resource_test.go

index 539e797295a321c68befe1315c7a8abd3ed3c7e1..0cb1309605dbc38a9690f0465e35146e21963d10 100644 (file)
@@ -301,3 +301,33 @@ 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))
+       }
+}
index 7e755bdbcce61d34c4ea42fdbbd30dbdc385d92a..7f52a7135581c2948df733441e7e202926b2dccf 100644 (file)
@@ -213,7 +213,7 @@ func (l *genericResource) Data() interface{} {
 }
 
 func (l *genericResource) Key() string {
-       return l.relTargetDirFile.path()
+       return l.RelPermalink()
 }
 
 func (l *genericResource) MediaType() media.Type {
index 46391527d33fad84786a13d1f8aca46035ca424c..7a0b8069d797c005643cbc7e89ef8b21180d1955 100644 (file)
@@ -52,7 +52,7 @@ func TestGenericResourceWithLinkFacory(t *testing.T) {
 
        c.Assert(r.Permalink(), qt.Equals, "https://example.com/foo/foo.css")
        c.Assert(r.RelPermalink(), qt.Equals, "/foo/foo.css")
-       c.Assert(r.Key(), qt.Equals, "foo.css")
+       c.Assert(r.Key(), qt.Equals, "/foo/foo.css")
        c.Assert(r.ResourceType(), qt.Equals, "css")
 }