Hi there.
I learnt about resources.ExecuteAsTemplate from Hugo’s docs. The example given there is:
{{ with resources.Get "css/template.css" }}
{{ with resources.ExecuteAsTemplate "css/main.css" $ . }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{ end }}
{{ end }}
Now suppose I’d like to minify the output of that template, i.e., main.css, which can be achieved simply by adding a minify step:
{{ with resources.Get "css/template.css" }}
{{ with resources.ExecuteAsTemplate "css/main.css" $ . | minify }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{ end }}
{{ end }}
So far, everything works as expected. But then I decide to rename template.css to, say, template.css.tmpl, since the template syntax isn’t valid CSS and triggers editor warnings (in contrast with HTML templates). The code above is changed accordingly:
{{ with resources.Get "css/template.css.tmpl" }}
{{ with resources.ExecuteAsTemplate "css/main.css" $ . | minify }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{ end }}
{{ end }}
It turns out, however, that this isn’t a valid solution. hugo server and hugo build throw the following error:
execute of template failed at <.RelPermalink>: error calling RelPermalink: MINIFY: failed to transform “css/main.css” (): minifier does not exist for mimetype
It looks like the mimetype is determined by the template rather than its output. Even thought this doesn’t cause a real problem (sticking to .css extension is fine), I definitely find it confusing and would love to learn why it’s the case.