Hugo

How do you asciify a url?

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 :smiley:

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 :slight_smile:

1 Like

:smiley: 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 ?

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. :upside_down_face: Everything works fine now,

I understand now :slightly_smiling_face: 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)

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 }}&amp;url={{ .Permalink }}" class="btn btn-icon btn-lg btn-twitter btn-round">
	<i class="fab fa-twitter-square"></i>
</a>