I had a working blog, no issues. Now I regenerated the site, and noticed the tags get generated as:
<a href="http://localhost:1313/tags/swift/">swift</a>
The < " >
characters end up being escaped, so they are no longer clickable links.
I noticed there’s safeURL
, but http and https
should be trusted, so it’s not that.
Otherwise, I don’t know where to start debugging. I just slapped together a website with a template I downloaded some years ago.
Initially I was using v0.123.8 but now I upgrade to v0.125.6 and I still get the same behavior.
Any help would be appreciated, let me know what information would be relevant.
You haven’t provided anything that anybody can start helping you with. Could you provide repo or live example.
I created a mostly blank repo that can be used to reproduce it:
The theme you’re using is very old and has been archived by the author.
The problem is here:
https://github.com/zwbetz-gh/cayman-hugo-theme/blob/master/layouts/post/single.html#L16
Instead of this…
{{ delimit $tags ", " }}
do this:
{{ delimit $tags ", " | safeHTML }}
Better yet, replace this…
{{ $tags := slice }}
{{ with .Params.tags }}
<div>
<strong>Tags: </strong>
{{ range . }}
{{ $href := print ("tags/" | absLangURL) (. | urlize) "/" }}
{{ $element := printf "<a href=\"%s\">%s</a>" $href . }}
{{ $tags = $tags | append $element }}
{{ end }}
{{ delimit $tags ", " }}
</div>
{{ end }}
…with something like this:
{{ with .GetTerms "tags" }}
<p>Tags:</p>
<ul>
{{ range . }}
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
{{ end }}
</ul>
{{ end }}
It’s a lot less fragile.
Thanks!
I think I have mistakenly deleted some of the contents of the theme folder, because I only saw a handful of css
and scss
folders, but not the layout
folder, so I was at complete loss on how to debug it.
system
Closed
May 8, 2024, 8:23pm
6
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.