HUGO

Error on update from 0.69.0 to 0.74.3, "can't give argument to non-function"

Something ugly in my code, must be.

Found this post about possibly a similar error, but there’s no point in pretending I get what’s going on with that one. Better I post the code and error here and hope you guys see again what I don’t.

The offending code ($listPageTypes is a slice earlier defined with Types for the paginator):

{{ $.Scratch.Set "listings" .Site.Params.listings }}
<!-- load paginator content by defined types -->
{{$paginator := ""}}
<!-- paginator for taxonomies -->
{{if or (eq .Type "categories" "tags")}}
{{ $.Scratch.Set "listings" .Site.Params.taxonomyListings }}
{{ $paginator = .Paginate (where .Data.Pages "Params.hidden" "!=" true) (.Params.listings | (default ($.Scratch.Get "listings")))}}
{{else}}
{{ $paginator = .Paginate (where (where .Site.RegularPages "Type" "in" $listPageTypes).ByDate.Reverse "Params.hidden" "!=" true) (.Params.listings | (default ($.Scratch.Get "listings")))}}
{{end}}

The error:

_default/list.html:15:4: executing "main" at <partial "paginator" .>: error calling partial: "c:\Hugo\sites\cloudnine-build-directory\layouts\partials\paginator.html:31:137": execute of template failed: template: partials/paginator.html:31:137: executing "partials/paginator.html" at <.Params.listings>: can't give argument to non-function default ($.Scratch.Get "listings")

The point of this code is to set a higher number of listings in the paginator for tags and cats.

Anyone see the problem?

(not tested), try to unwrap extra parenthesis on the default function

{{ $.Scratch.Set "listings" .Site.Params.listings }}
<!-- load paginator content by defined types -->
{{$paginator := ""}}
<!-- paginator for taxonomies -->
{{if or (eq .Type "categories" "tags")}}
{{ $.Scratch.Set "listings" .Site.Params.taxonomyListings }}
++ {{ $paginator = .Paginate (where .Data.Pages "Params.hidden" "!=" true) (.Params.listings | default ($.Scratch.Get "listings"))}}
{{else}}
++ {{ $paginator = .Paginate (where (where .Site.RegularPages "Type" "in" $listPageTypes).ByDate.Reverse "Params.hidden" "!=" true) (.Params.listings | default ($.Scratch.Get "listings"))}}
{{end}}

Thanks. That works. Still figuring out the syntax.

{{ $paginator = .Paginate (where .Data.Pages "Params.hidden" "!=" true) (.Params.listings | default ($.Scratch.Get "listings"))}}

On the topic of the update, while I have you here, I found npm uglifying and concatenating prior to minifying and fingerprinting in hugo production build worked great.

Now this js.Build thing does basically the same as npm uglify, only faster (and in the hugo pipe)?

Obviously that’s a yes, but if you could print a big fat yes after this that would be great (npm uglify doesn’t stand up to js.Build)?

Thanks again!

i never compared the output of npm uglify vs js.Build.

as js.Build is based on esbuild, you may want to read all it’s capabilities on the esbuild repo readme.

I’m not heavy js user, i only include small js libs + my own code to hook html element, so it’s pretty simple.
i would say YES,
the ability to bundle and minify javascript without running nodejs is already 100+ points for me.

Good to know, thanks. I don’t use a ton of javascript either. I’m using mostly PHP on the backend for dynamic server side. Looking forward to learning more about integrating dynamic server-side action with hugo builds under the same url. If I had more time I would love to learn more go!

I use npm html-minifier instead of hugo minifier. Didn’t yet mess around too much with hugo minifier options, but html-minifier was better output when I did. Build is scripted and shortcutted, so not a big problem, but will be nice to cut out the npm javascript uglifier anyway.

Cheers

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.