Skip to content

Commit

Permalink
Fix rebuild with resources.Concat
Browse files Browse the repository at this point in the history
Fixes #12017
  • Loading branch information
bep committed Feb 9, 2024
1 parent 0851c17 commit 5cbb91c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
24 changes: 24 additions & 0 deletions hugolib/rebuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1261,3 +1261,27 @@ func BenchmarkRebuildContentFileChange(b *testing.B) {
// fmt.Println(bb.LogString())
}
}

func TestRebuildConcat(t *testing.T) {
files := `
-- hugo.toml --
baseURL = "https://example.com"
disableLiveReload = true
-- assets/a.css --
a
-- assets/b.css --
b
-- layouts/index.html --
{{ $a := resources.Get "a.css" }}
{{ $b := resources.Get "b.css" }}
{{ $ab := slice $a $b | resources.Concat "ab.css" }}
ab: {{ $ab.Content | safeCSS }}
`
b := TestRunning(t, files)

b.AssertFileContent("public/index.html", "ab: a\nb\n")

b.EditFileReplaceAll("assets/a.css", "a", "a edited").Build()

b.AssertFileContent("public/index.html", "ab: a edited\nb\n")
}
11 changes: 11 additions & 0 deletions resources/resource_factories/bundler/bundler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"path"

"github.com/gohugoio/hugo/common/hugio"
"github.com/gohugoio/hugo/identity"
"github.com/gohugoio/hugo/media"
"github.com/gohugoio/hugo/resources"
"github.com/gohugoio/hugo/resources/resource"
Expand Down Expand Up @@ -82,6 +83,11 @@ func (r *multiReadSeekCloser) Close() error {
func (c *Client) Concat(targetPath string, r resource.Resources) (resource.Resource, error) {
targetPath = path.Clean(targetPath)
return c.rs.ResourceCache.GetOrCreate(targetPath, func() (resource.Resource, error) {
var idm identity.Manager = identity.NopManager
if c.rs.Cfg.Watching() {
idm = identity.NewManager("concat")
}

var resolvedm media.Type

// The given set of resources must be of the same Media Type.
Expand All @@ -91,6 +97,10 @@ func (c *Client) Concat(targetPath string, r resource.Resources) (resource.Resou
return nil, fmt.Errorf("resources in Concat must be of the same Media Type, got %q and %q", r.MediaType().Type, resolvedm.Type)
}
resolvedm = r.MediaType()
identity.WalkIdentitiesShallow(r, func(depth int, id identity.Identity) bool {
idm.AddIdentity(id)
return false
})
}

concatr := func() (hugio.ReadSeekCloser, error) {
Expand Down Expand Up @@ -136,6 +146,7 @@ func (c *Client) Concat(targetPath string, r resource.Resources) (resource.Resou
LazyPublish: true,
OpenReadSeekCloser: concatr,
TargetPath: targetPath,
DependencyManager: idm,
})
if err != nil {
return nil, err
Expand Down

0 comments on commit 5cbb91c

Please sign in to comment.