Below every post on my webpage there are share buttons displayed. Because I’ve recently joined mastodon, I wanted to include a “Share on Mastodon” button.

So, after doing some research, I’ve used the content at to make it all work.

Because the modified jekyll theme I use is based on Type-on-Strap, my share buttons are located at _includes/share_buttons.html. I’ve added the following code to it:

{% if site.theme_settings.share_buttons.mastodon %}
       <a href="" onclick="shareMastodon();">
		<i class="fab fa-mastodon fa-2x" aria-hidden="true"></i>
		<span class="sr-only">{{ site.theme_settings.str_share_on }} Mastodon</span>
function shareMastodon() { 
       	// Prefill the form with the user's previously-specified Mastodon instance, if applicable
       	var default_url = localStorage['mastodon_instance']; 

       	// If there is no cached instance/domain, then insert a "https://" with no domain at the start of the prompt. 
       	if (!default_url)
               default_url = "https://"; 

       	var instance = prompt("Enter your instance's address: (ex:", default_url);
       	if (instance) { 
               	// Handle URL formats
               	if ( !instance.startsWith("https://") && !instance.startsWith("http://") )
                       	instance = "https://" + instance;  

               	// Get the current page's URL
               	var url   = window.location.href;
               	// Get the page title from the og:title meta tag, if it exists.
               	var title = document.querySelectorAll('meta[property="og:title"]')[0].getAttribute("content"); 
               	// Otherwise, use the <title> tag as the title
               	if (!title)    var title = document.getElementsByTagName("title")[0].innerHTML;
               	// Handle slash
               	if ( !instance.endsWith("/") )
                       	instance = instance + "/"; 

               	// Cache the instance/domain for future requests
               	localStorage['mastodon_instance'] = instance; 

               	// Hashtags 
               	hashtags     =  "";

               	// Tagging users, such as offical accounts or the author of the post 
               	var author   = ""; 

               	// Create the Share URL
               	// https://someinstance.tld/share?text=URL%20encoded%20text
               	mastodon_url = instance + "share?text=" + encodeURIComponent(title + "\n\n" + url + "\n\n" + hashtags + " " + author);

               	// Open a new window at the share location   
      , '_blank');

Now, let’s write some blog post about it and test if it’s work ;)