Add html tag to end of hugo {{.Permalink}}?

So I want to edit a link on my website to point to a permalink, while also adding a “#post-top” to the end of the url. Currently I have something like this… <span><a href="{{ .Permalink }}#post-top">
This adds the tag to the end of the line, but the permalink still has a “/” character at the end, so I end up with something like

which breaks the html tag navigation. Is there any way to edit the permalink string so I can do this? (I’ve tried modifying my config but it seems that is mainly for the saving and placement of files rather than urls?)

Perhaps there’s a better way to do this, but for the moment…

{{ $fragment := "post-top" }}
{{ $url := printf "%s#%s" (strings.TrimRight "/" .Permalink) $fragment }}
<a href="{{ $url }}">foo</a>

And you could certainly reduce that to one line.

1 Like

Works well, thank you!

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