diff --git a/hugolib/resource_chain_test.go b/hugolib/resource_chain_test.go index b49e1ee72..d504b7d75 100644 --- a/hugolib/resource_chain_test.go +++ b/hugolib/resource_chain_test.go @@ -36,12 +36,15 @@ func TestResourceChain(t *testing.T) { {{ $sass := resources.Get "sass/styles3.sass" | toCSS }} {{ $scssCustomTarget := resources.Get "scss/styles2.scss" | toCSS (dict "targetPath" "styles/main.css") }} {{ $scssCustomTargetString := resources.Get "scss/styles2.scss" | toCSS "styles/main.css" }} -{{ $scssMin := resources.Get "scss/styles2.scss" | toCSS | minify }} +{{ $scssMin := resources.Get "scss/styles2.scss" | toCSS | minify }} +{{ $scssFromTempl := ".{{ .Kind }} { color: blue; }" | resources.FromString "kindofblue.templ" | resources.ExecuteAsTemplate "kindofblue.scss" . | toCSS (dict "targetPath" "styles/templ.css") | minify }} +{{ $bundle1 := slice $scssFromTempl $scssMin | resources.Concat "styles/bundle1.css" }} T1: Len Content: {{ len $scss.Content }}|RelPermalink: {{ $scss.RelPermalink }}|Permalink: {{ $scss.Permalink }}|MediaType: {{ $scss.MediaType.Type }} T2: Content: {{ $scssMin.Content }}|RelPermalink: {{ $scssMin.RelPermalink }} T3: Content: {{ len $scssCustomTarget.Content }}|RelPermalink: {{ $scssCustomTarget.RelPermalink }}|MediaType: {{ $scssCustomTarget.MediaType.Type }} T4: Content: {{ len $scssCustomTargetString.Content }}|RelPermalink: {{ $scssCustomTargetString.RelPermalink }}|MediaType: {{ $scssCustomTargetString.MediaType.Type }} T5: Content: {{ $sass.Content }}|T5 RelPermalink: {{ $sass.RelPermalink }}| +T6: {{ $bundle1.Permalink }} `) }, func(b *sitesBuilder) { b.AssertFileContent("public/index.html", `T1: Len Content: 24|RelPermalink: /scss/styles2.css|Permalink: http://example.com/scss/styles2.css|MediaType: text/css`) @@ -50,6 +53,10 @@ T5: Content: {{ $sass.Content }}|T5 RelPermalink: {{ $sass.RelPermalink }}| b.AssertFileContent("public/index.html", `T4: Content: 24|RelPermalink: /styles/main.css|MediaType: text/css`) b.AssertFileContent("public/index.html", `T5: Content: .content-navigation {`) b.AssertFileContent("public/index.html", `T5 RelPermalink: /sass/styles3.css|`) + b.AssertFileContent("public/index.html", `T6: http://example.com/styles/bundle1.css`) + + b.AssertFileContent("public/styles/templ.min.css", `.home{color:blue}`) + b.AssertFileContent("public/styles/bundle1.css", `.home{color:blue}body{color:#333}`) }}, diff --git a/resource/transform.go b/resource/transform.go index fcb101438..005ede767 100644 --- a/resource/transform.go +++ b/resource/transform.go @@ -188,12 +188,25 @@ type transformedResource struct { Resource } +type readSeeker struct { + io.Reader + io.Seeker + io.Closer +} + +func (r *readSeeker) Close() error { + return nil +} + +func (r *readSeeker) Seek(offset int64, whence int) (int64, error) { + panic("Seek is not supported by this io.Reader") +} + func (r *transformedResource) ReadSeekCloser() (ReadSeekCloser, error) { - rc, ok := r.Resource.(ReadSeekCloserResource) - if !ok { - return nil, fmt.Errorf("resource %T is not a ReadSeekerCloserResource", rc) + if err := r.initContent(); err != nil { + return nil, err } - return rc.ReadSeekCloser() + return &readSeeker{Reader: strings.NewReader(r.content)}, nil } func (r *transformedResource) transferTransformedValues(another *transformedResource) {