-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document urlquery
function
#1627
Comments
@schnerring Thanks for this; much appreciated. Note that your example can be addressed with the querify function.
|
I understand that, but my actual requirement is a bit more complex. Here is the partial I use as "social provider": {{ $url := .Permalink }}
{{ $title := .Title }}
{{ with $.Site.Params.socialShare }}
<div class="social-share">
<strong>Share this post: </strong>
{{ range . }}
{{ $href := .formatString }}
{{ $href := replace $href "{url}" (urlquery $url) }}
{{ $href := replace $href "{title}" (urlquery $title) }}
<a href="{{ $href | safeURL }}" target="_blank" rel="noreferrer">
{{ if eq .icon "Mail" }}
{{ partial "icons/tabler-icon.html" .icon }}
{{ else }}
{{ partial "icons/simple-icon.html" .icon }}
{{ end }}
</a>
{{ end }}
</div>
{{ end }} This allows me to add social share buttons via Hugo config like this [[params.socialShare]]
icon = "Facebook"
formatString = "https://www.facebook.com/sharer.php?u={url}"
[[params.socialShare]]
icon = "Reddit"
formatString = "https://reddit.com/submit?url={url}&title={title}"
[[params.socialShare]]
icon = "Twitter"
formatString = "https://twitter.com/intent/tweet?url={url}&text={title}"
[[params.socialShare]]
icon = "LinkedIn"
formatString = "https://www.linkedin.com/sharing/share-offsite/?url={url}"
[[params.socialShare]]
icon = "WhatsApp"
formatString = "whatsapp://send/?text={title}%20{url}"
[[params.socialShare]]
icon = "Tumblr"
formatString = "https://www.tumblr.com/widgets/share/tool?canonicalUrl={url}&title={title}&caption={title}" As the query string parameter structure differs depending on the network, I tried doing something like |
So from what I understand Looking at the go template docs I also found the
So is it really an undocumented Hugo feature or just a go templating feature? |
Both. |
* Add urlquery function docs Fixes #1627 * Update content/en/functions/urlquery.md * Update content/en/functions/urlquery.md * Update content/en/functions/urlquery.md * Update content/en/functions/urlquery.md * Update content/en/functions/urlquery.md * Update content/en/functions/urlquery.md * Update content/en/functions/urlquery.md * Update content/en/functions/urlquery.md Co-authored-by: Joe Mooring <[email protected]>
Consider the following example:
The issue I've had is that I want to "percent-encode"
.Permalink
. People have had this issue before:I've poked around the Hugo code base and found an undocumented built-in Hugo function
urlquery
:https://github.com/gohugoio/hugo/blob/3d5dbdcb1a11b059fc2f93ed6fadb9009bf72673/tpl/internal/go_templates/texttemplate/funcs.go#L51
https://github.com/gohugoio/hugo/blob/3d5dbdcb1a11b059fc2f93ed6fadb9009bf72673/tpl/internal/go_templates/texttemplate/funcs.go#L738-L742
It's a thin wrapper around
url.QueryEscape
and perfectly solves my issue:Is the function here to stay and just misses documentation?
The text was updated successfully, but these errors were encountered: