Hugo v0.55.6 error calling ressources.Concat

Hi everyone.

I got an error when trying to bundle my css resources inside a partial :
error calling Concat: slice []interface {} not supported in concat

Here is the partial, pretty straightforward:

{{ $css := slice }}
{{ range .components }}
  {{ if not .critical }}
  {{ $r := resources.Get (printf "components/%s.css" .id) }}
  {{ $css = $css | append $r }}
  {{ end }}
{{ end }}

{{ $css := $css | resources.Concat "bundle.min.css" | postCSS | fingerprint }}
<link rel="stylesheet" href="{{ $css.Permalink | relURL }}" integrity="{{ $css.Data.Integrity }}" media="screen">

I’m on Windows OS 64, then I run

set hugov="0.55.6"
/hugo/bin/%hugov%/hugo.exe version
/hugo/bin/%hugov%/hugo.exe -v server --bind=0.0.0.0 --baseURL=http://0.0.0.0:1313 --navigateToChanged --disableFastRender

I tried on different version of hugo, on extended, I also print the interface on screen, seems everything’s fine before concat func, I’ve got a go slice with page ressource inside as interface.
I saw this error happened back in 2018, bep commit a fix to let the arg type on concat func be more permissive. I’ve been looking for a workaround there. Got a snippet using Scratch instead of slice. I tried but still same error.

Here is the verbose log

INFO 2019/06/14 11:05:20 No translation bundle found for default language "en"
INFO 2019/06/14 11:05:20 Translation func for language en not found, use default.
INFO 2019/06/14 11:05:20 i18n not initialized; if you need string translations, check that you have a bundle in /i18n that matches the site language or the default language.
INFO 2019/06/14 11:05:20 Using config file:
Building sites … INFO 2019/06/14 11:05:20 syncing static files to C:\Hugo\Sites\blog\
INFO 2019/06/14 11:05:20 No Static directory found
INFO 2019/06/14 11:05:20 found taxonomies: map[string]string{"category":"categories", "tag":"tags"}
WARN 2019/06/14 11:05:20 found no layout file for "HTML" for "taxonomyTerm": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
WARN 2019/06/14 11:05:20 found no layout file for "HTML" for "section": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
WARN 2019/06/14 11:05:20 found no layout file for "HTML" for "taxonomyTerm": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
INFO 2019/06/14 11:05:20 postcss: use config file C:\Hugo\Sites\blog\postcss.config.js
INFO 2019/06/14 11:05:22 postcss: use config file C:\Hugo\Sites\blog\postcss.config.js
INFO 2019/06/14 11:05:24 postcss: use config file C:\Hugo\Sites\blog\postcss.config.js
INFO 2019/06/14 11:05:26 postcss: use config file C:\Hugo\Sites\blog\postcss.config.js
ERROR 2019/06/14 11:05:28 render of "page" failed: "C:\Hugo\Sites\blog\themes\dev\layouts\_default\single.html:14:27": execute of template failed: template: _default/single.html:21:5: executing "_default/single.html" at <partial "assetsLoader.gohtml" (dict "c" . "components" .Params.components)>: error calling partial: "C:\Hugo\Sites\blog\themes\dev\layouts\partials\assetsLoader.gohtml:14:27": execute of template failed: template: partials/assetsLoader.gohtml:14:27: executing "partials/assetsLoader.gohtml" at <resources.Concat>: error calling Concat: slice []interface {} not supported in concat
ERROR 2019/06/14 11:05:28 render of "home" failed: "C:\Hugo\Sites\blog\themes\dev\layouts\index.html:14:27": execute of template failed: template: index.html:27:5: executing "index.html" at <partial "assetsLoader.gohtml" (dict "c" . "components" .Params.components)>: error calling partial: "C:\Hugo\Sites\blog\themes\dev\layouts\partials\assetsLoader.gohtml:14:27": execute of template failed: template: partials/assetsLoader.gohtml:14:27: executing "partials/assetsLoader.gohtml" at <resources.Concat>: error calling Concat: slice []interface {} not supported in concat
Total in 7911 ms
Error: Error building site: failed to render pages: render of "page" failed: "C:\Hugo\Sites\blog\themes\dev\layouts\_default\single.html:14:27": execute of template failed: template: _default/single.html:21:5: executing "_default/single.html" at <partial "assetsLoader.gohtml" (dict "c" . "components" .Params.components)>: error calling partial: "C:\Hugo\Sites\blog\themes\dev\layouts\partials\assetsLoader.gohtml:14:27": execute of template failed: template: partials/assetsLoader.gohtml:14:27: executing "partials/assetsLoader.gohtml" at <resources.Concat>: error calling Concat: slice []interface {} not supported in concat

Home someone can help with that.
Thank you.

What is .components ?
You’ll need to share your whole project, or create a minimal reproducible example and share that.

Hi @zwbetz, sorry for that…

I have a JSON Front Matter like this on all Types (.md files)

I pass an array of “components” to be rendered, then assetsLoader.gohtml & criticalLoader.gohtml partials handle assets (resources) loading (bundle + html permalink).

{
  "title": "string",
  "desc": "string",
  "components": [
    {
      "name": "string",
      "id": "string",
      "critical": boolean,
      "data": {
        "title": "string",
        "src": "name.jpg",
        "alt": "string",
        "desc": "string"
      }
    }, 
{....another component}
]
}

Then in my layouts
layouts/_default/baseof.html, layouts/_defaults/single.html & layouts/index.html

{{ $context := . }}

<!DOCTYPE html>
<html>

<head>
  <title>{{ .Title }}</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
  <meta name="description" content={{ .Desc }}>
  {{ partial "criticalLoader.gohtml" (dict "c" $context "components" .Params.components) }}
</head>

<body>
  <nav>
    {{ partial "vMenu1.gohtml" . }}
  </nav>
  {{ range .Params.components }}
  {{ partial (printf "%s.gohtml" .id) (dict "c" $context "data" .data "id" .id) }}
  {{ end }}
  {{ partial "assetsLoader.gohtml" (dict "c" $context "components" .Params.components) }}
</body>

</html>

component.id then refers to files in assets/components/$id.css

if I print the $css input on hugo concat pipe I’ve got a perfectly valid go slice of Page.Resources struct

[Resource(css: components/vList1.css) Resource(css: components/vTestimonial1.css) Resource(css: components/vGallery1.css)]

Note: If I directly use the syntax below, it works using concat. I’ve got the same type as arg, a go []slice of Page.Resources.

{{ $file := resources.Get "file" }}
{{ $anotherFile := resources.Get "anotherFile" }}
{{ $css := slice $file $another-file| resources.Concat "bundle.min.css" | postCSS | fingerprint }}

As of now
I use the code below as a workaround, works perfectly. But having assets bundling would be better to avoid extra server round trips.

{{ range .components }}
  {{ if not .critical }}
  {{ $css := resources.Get (printf "components/%s.css" .id) | postCSS | fingerprint }}
  <link rel="stylesheet" href="{{ $css.Permalink | relURL }}" integrity="{{ $css.Data.Integrity }}" media="screen">
  {{ end }}
{{ end }}

If it’s still unclear let me know I will post a sample.
Thank you have a nice day.

@zwbetz Okay once again sorry for that…
I found the problem trying to replicate a small use case.
I had one JSON front matter with no “components” field leading to empty interface as arg to concat func…

Once again thank you for your help and quick reply. Hugo community is the best.
Cheers.

3 Likes