I’m building my own social share buttons using this CSS Tricks post. I can’t find how to apply URL encoding to my link (have had a look through all the Functions). I’m sure it’s really obvious, or more likely called something else!
It works insofar as the URL is displayed but it’s not URL encoded. I’m after
https%3A%2F%2Fwww.forestgarden.wales
rather than
https://www.forestgarden.wales
There is a lot of golang stuff out there on URL encoding but I’m only an occasional web developer now, and just writing HTML makes my eyeballs ache! Thought there might be a simple Hugo function.
Edit: Well, nevermind. I’m getting that result because I was hardcoding the permalink of the url you gave as already encoded. I see your issue now. Yeah am not sure there is a function for what you want.
Now, you could write some find-n-replace logic using replaceRE that may meet your needs.
That looks like it’s working, thank you so much I think the thing is, it’s such a small thing to do, hardly worth creating a whole Hugo function when you can do what you’ve done.
I’ve been having the same issue. I’ve poked around in the Hugo code base and found the solution. There’s an undocumented built-in Hugo function wrapping the Golang url.QueryEscape function: