I’m trying to create an easy way to mark pages on my site as deleted, so that webmentions work properly. What I have in mind is having a front matter deleted variable that would make Hugo create a .htaccess file containing Redirect 410 index.html.
and added “htaccess” for page to the [outputs] section. Then I created layouts/_default/single.htaccess:
{{ with .Params.deleted }}Redirect 410 index.html{{ end }}
It almost works. .htaccess is created for every page, and for those pages that have deleted = true in the front matter, it contains the text. But…
But every line of the created .htaccess files ends with $ sign. I’ve read the documentation, the issues on GitHub, googled extensively and searched the forum, but I still can’t figure out where these $s come from and how to get rid of them.
I’m sure there’s something obvious I’m missing, but what is it?
I figured as much, but where can it be? I mean, isn’t my layouts/_default/single.htaccess supposed to basically start with the clean state (empty file) and then add what I explicitly asked for?
I figured out a workaround, but still don’t understand the underlying mechanics. And judging by the workaround, it looks like somewhere something gets parsed wrong.
The working layouts/_default/single.htaccess I ended up with looks like this:
{{- with .Params.deleted -}}Redirect 410 "{{- $.RelPermalink -}}"{{- printf "\n" -}}
{{- end -}}
So, in essence, “dashing out” all the curly braces removes the $ signs at the end of every line, with the added benefit of not even creating the empty .htaccess where it isn’t needed.
Judging from all I know about Go templates, it shouldn’t work this way.