nobby
July 10, 2019, 11:41pm
1
I’ve got a link in layout/products/single.html
:
https://example.com/hello-world/
which I’d like to ASCIIfy, so it becomes:
https://example.com/hello%20world/
I’ve looked through the docs but can’t find a function that will give me that output. I must be missing something?
I’ve tried safeHTML, htmlUnescape, htmlEscape, plainify the works
zwbetz
July 11, 2019, 12:18am
2
I don’t know of a hugo function for this either. I would do it yourself via the replace
function. Or do it with JS.
PS the character encoding for -
is %2D
1 Like
nobby
July 11, 2019, 12:20am
3
Thanks.
Alright, so in that case, I’ll need to add a replace statement to cover both for " " and “-”.
I’m sorry if this is out of hand in some way, but can you explain why you need to use %20 ?
nobby
July 11, 2019, 6:29pm
5
Bruno, not at all.
I was trying to build a twitter sharing button, which has the following construct:
https://twitter.com/intent/tweet/?text={{.Title}}&url={{.Permalink}}
For some reason, the {{.Title}}
was not showing up when I clicked the link, but {{.Permalink}}
was showing correctly. On the examples that I came across, the titles were all using ASCII and HTML codes. This had me puzzled for a while, hence the question. But it all seemed strange. A few hours later, I noticed that I had forgotten to add text=
to the link. Everything works fine now,
I understand now it helps when you share the end result you need to achieve because sometimes there is another path to take.
(And now that I think about it, I never got around to adding share Buttons to my website)
nobby
July 11, 2019, 7:43pm
7
For sure.
I found this link to be helpful for building sharing buttons without js and tracking:
That link saved me a lot of work @nobby , thank you!
Also, I didn’t need any find-and-replace:
<a href="https://twitter.com/intent/tweet/?text={{ .Title }}&url={{ .Permalink }}" class="btn btn-icon btn-lg btn-twitter btn-round">
<i class="fab fa-twitter-square"></i>
</a>