I’m trying to add a LinkedIn share button to badges in a Discourse-hosted community I’m an admin in.
To this end, I’m trying to use this Plugin Outlet. I included the following code in the head section of a theme.
<script type='text/x-handlebars' data-template-name='/connectors/badge-contents-top/linkedin-button'>
<a href="https://www.linkedin.com/profile/add?certUrl=https://community.my_community.io{{@outletArgs.url}}" class="linkedin-share-button">
<img src="https://download.linkedin.com/desktop/add2profile/buttons/en_US.png " alt="LinkedIn Add to Profile button">
</a>
</script>
Please note href
attribute: https://www.linkedin.com/profile/add?certUrl=https://community.my_community.io/{{@outletArgs.url}}
.
The @outletArgs.url
value looks something like https://community.my_community.io/badges/<badge_id>/<badge_name>?username=<username>
. I want to focus on the username=<username>
part.
The URL is not encoded, the equal sign is being passed literally, so when the browser processes https://www.linkedin.com/profile/add?certUrl=https://community.my_community.io/https://community.my_community.io/badges/<badge_id>/<badge_name>?username=<username>
, it ignores =<username>
.
How do I encode the URL here?