I made it work by pure luck, but I can’t figure out why it works, and why it doesn’t work when I try to do it logically.
I’m using webmention.js on my site, and I want it to show webmentions even in development mode. I need to pass it the address of the page, but it wouldn’t work in dev mode (i.e. hugo server
), because the page address would start with http://localhost:1313/
instead of my site’s domain, so I’m trying to:
{{- $base := partialCached "assumed-base.html" . -}}
and then use
{{ printf `%s%s` $base .RelPermalink }}
to get “real” URL. Now, the logical assumed-base.html
partial in my head looks somewhat like
{{- if eq hugo.Environment "development" -}}
{{- return "https://mysite.tld" -}}
{{- end -}}
{{- return (strings.TrimSuffix "/" .Site.BaseURL) -}}
But it doesn’t work. It works perfectly in dev environment (hugo server
), but fails with
execute of template failed: template: partials/assumed-base.html:4:4: executing "partials/assumed-base.html" at <return>: wrong number of args for return: want 0 got 1
Somehow in line 2 one argument for return is allright, but in line 4 it is wrong? Why?
I could make it work by changing assumed-base.html
a little:
{{- if eq hugo.Environment "development" -}}
{{- return "https://mysite.tld" -}}
{{- end -}}
{{ .Site.BaseURL }}
{{- return -}}
I don’t understand why this works. I don’t understand why I don’t get the extra /
between base and relative path (the one I was trying to preempt with strings.TrimSuffix
). And this lack of understanding bothers me.
Can someone please help me out here?