mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-27 22:09:53 +02:00
tpl/collections: Fix handling of different interface types in Slice
In Hugo `0.49` we improved type support in `slice`. This has an unfortunate side effect in that `resources.Concat` now expects something that can resolve to `resource.Resources`. This worked for most situations, but when you try to `slice` different `Resource` objects, you would be getting `[]interface {}` and not `resource.Resources`. And `concat` would fail: ```bash error calling Concat: slice []interface {} not supported in concat. ``` This commit fixes that by simplifying the type checking logic in `Slice`: * If the first item implements the `Slicer` interface, we try that * If the above fails or the first item does not implement `Slicer`, we just return the `[]interface {}` Fixes #5269
This commit is contained in:
@@ -238,6 +238,10 @@ T1: Content: {{ $combined.Content }}|RelPermalink: {{ $combined.RelPermalink }}|
|
||||
{{ $combinedText := . | resources.Concat "bundle/concattxt.txt" }}
|
||||
T2: Content: {{ $combinedText.Content }}|{{ $combinedText.RelPermalink }}
|
||||
{{ end }}
|
||||
{{/* https://github.com/gohugoio/hugo/issues/5269 */}}
|
||||
{{ $css := "body { color: blue; }" | resources.FromString "styles.css" }}
|
||||
{{ $minified := resources.Get "css/styles1.css" | minify }}
|
||||
{{ slice $css $minified | resources.Concat "bundle/mixed.css" }}
|
||||
`)
|
||||
}, func(b *sitesBuilder) {
|
||||
b.AssertFileContent("public/index.html", `T1: Content: ABC|RelPermalink: /bundle/concat.txt|Permalink: http://example.com/bundle/concat.txt|MediaType: text/plain`)
|
||||
|
Reference in New Issue
Block a user