Url scheme doesn't work

I’m trying to share links to my social media on main page at PaperMod theme using socialIcons functionality, but it seems URL schemes like xmpp: or matrix: aren’t working properly however mailto: for email works with no problem, syntax for using them is like:

socialIcons:
  - name: email
    url: mailto:name@email.com

so if I click on the icon for email it work perfectly but if I replace it with XMPP or matrix

socialIcons:
  - name: xmpp
    url: xmpp:address@instance.com

It won’t work like this, however if i write it down directly into the browser address bar it redirects me to the XMPP account.
What can I do about it?

Configured as shown above, if you inspect the rendered page you will see this:

<a href="#ZgotmplZ" target="_blank" rel="noopener noreferrer me" title="Xmpp">
...
</a>

See the “ZgotmplZ” bit? If you search the documentation for “ZgotmplZ” you will see a link to:
https://gohugo.io/functions/safeurl/

Without safeURL , only the URI schemes http: , https: and mailto: are considered safe by Go templates. If any other URI schemes (e.g., irc: and javascript: ) are detected, the whole URL will be replaced with #ZgotmplZ .

If you look at how the paperMod theme renders the social icons…

…you can see that the author doesn’t pass the URL through the safeURL function. Please raise an issue with the theme author.

In the interim, you can override that partial template with your own:

mkdir -p layouts/partials/templates
cp themes/hugo-PaperMod/layouts/partials/social_icons.html layouts/partials/
cp themes/hugo-PaperMod/layouts/partials/templates/schema_json.html layouts/partials/templates

Edit layouts/partials/social_icons.html, changing this:

href="{{ trim .url " " }}"

to this:

href="{{ trim .url " " | safeURL }}"

Edit layouts/partials/templates/schema_json.html, changing this:

{{ trim $e.url " " }}

to this:

{{ trim $e.url " " | safeURL }}
1 Like

Thank you very much now it’s working. I will raise an issue as soon as possible.
also the default theme name is set to PaperMod, you might want to fix the path for future references themes/PaperMod/...

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