I was tired of manually sharing my blog articles on my Twitter, LinkedIn and Facebook accounts so I decided to automate the process using Jekyll front matter variables, RSS feeds, and IFTTT applets.
Choose What to Share and How
First, for each post I want to share on social media, I include additional front matter variables.
Since twitter
, facebook
, and linkedin
are indented, sharing
becomes an object. This object properties can be accessed using the dot notation page.sharing.twitter
or the array notation page.sharing["twitter"]
.
The sharing section is optionnal so is each social media site in the list. If only one of the site has a value, the post will be shared only on that site.
Twitter has a 140 characters limitation and any link is using 23 characters. This restricts the length of your message to 116 characters if you keep one for the space before the link to your post.
Define an RSS Feed Layout
I need one RSS feed per social media site, so I created a sharing_feed.xml
file in the _layouts
folder to avoid repetition.
The important parts are:
- The use of the
page.sharing_site
variable which contains the social media site of the current RSS feed. - The
posts
variable I assign to only the subset of posts I want to share on that specific social media site. - The
limit:5
on thefor
loop to limit the size of the RSS feed to a minimum. I don’t plan to create more than 5 posts in a 15 minutes timeframe (IFTTT applets run every 15 minutes). - The
<title>
of RSS items contains the text to share. - The
<link>
of RSS items contains the link to the blog post to share.
Create the RSS Feeds
Creating the RSS feeds is very easy with this layout. I created one file per social media site. The sharing_site
front matter variable value need to match the post front matter variable names.
Twitter.xml
Facebook.xml
Create the IFTTT Applets
In IFTTT, I created one applet for each of the social media site.
Twitter.xml
- This
- Service: Feed
- Trigger: New feed item
- Feed URL: https://www.jflh.ca/feeds/twitter.xml
- That
- Service: Twitter
- Action: Post a tweet
- Tweet text: {{EntryTitle}} {{EntryUrl}}
Facebook.xml
- This
- Service: Feed
- Trigger: New feed item
- Feed URL: https://www.jflh.ca/feeds/facebook.xml
- That
- Service: Facebook
- Action: Create a link post
- Link URL: {{EntryUrl}}
- Message: {{EntryTitle}}
- This
- Service: Feed
- Trigger: New feed item
- Feed URL: https://www.jflh.ca/feeds/linkedin.xml
- That
- Service: LinkedIn
- Action: Share an update
- Status: {{EntryTitle}} {{EntryUrl}}
Workflow
With that in place, everytime I commit a new blog post, I can fill in the messages I want to share on social media sites. Under 15 minutes, the IFTTT applets are triggered and my post is shared automatically.