Mild-Mannered Canadian Fury

Doug Stephen is Politely Peeved

An absolutely ridiculous hack to syndicate Octopress to Twitter via IFTTT with support for linklog posts

Fri, 31 Aug 2012 «permalink»

Prewarning: This technique is not proper semantics. It’s bad. Very bad. But it does what I want it to do.

I’d been looking for a way to syndicate this blog to my Twitter feed for a while, and eventually stumbled upon a few posts around the web that pointed out something that should have been obvious to me from the start: I can use IFTTT.

If you’re not familiar with IFTTT, it’s a sort of Automator for web services. It operates on “Triggers”, with each trigger belong to a channel. For example, you can connect IFTTT to your Twitter account, and then hook in to several of the Twitter triggers available. The result of a Trigger is to perform an action on another channel. It’s where the name of the service comes from; IFTTT stands for “If This, Then That”. A completed IFTTT hook is called a Recipe.

Example of a real-world recipe that I use: IF I favorite a tweet, THEN save a copy of that tweet in Evernote.

IFTTT has an RSS channel, so I set up a recipe to use IFTTT to syndicate the blog’s feed to my Twitter: Every time a new post shows up in my RSS feed, make a tweet about it with a link to the article. IFTTT doesn’t get along well with Feedburner (then again, who does?), so I had to point it to the raw atom.xml file. This worked great, except for one little hiccup: The way I had set up the Recipe, IFTTT was posting a link to the article by pulling it out of whatever the RSS Entry Title was linked to. I link all of my linklog posts to their source via the title, and I don’t want to change this behavior. I’m writing to spread information and contribute to the greater culture of the Internet, not drive page views. So how could I fix this?

Interestingly enough, IFTTT provides an “ingredient” for the RSS trigger that pulls out the URL of the first image that shows up in the entry. So I did something naughty. In the template for my Octopress atom.xml file, I added a little ugly hack:

Hacked atom.xml
<content type="html">
    <![CDATA[<img src="{{ site.url }}{{ post.url }}" width=0 height=0 hidden="hidden" style="display:none;" alt="" title="" />]]>

    <![CDATA[{{ post.content | expand_urls: site.url | cdata_escape }}<a rel="full-article" href="{{ site.url }}{{ post.url }}">🍁 {{ post.date_formatted }} «PERMALINK»</a>]]>

The hack is that first line of CDATA; an image whose source url is the absolute identifier for the current post. This is always the first image in the entry, and so I can use IFTTT to pull out that URL and use it in the generated tweet. Of course, the RSS spec doesn’t respect all of those width and height and hidden and inline style attributes, but I put them in there just in case someone is using a random reader that does render those things. It seems to work in Google Reader’s web view, but Reeder shows a broken image box. I’m going to have to fix this at some point, most likely using clever redirects on the server side, but until then, this is the best way I could find to syndicate my blog to my Twitter account using IFTTT.

I’m open to ideas from anyone out there who is smarter than I am and can figure out a more semantic, less ugly way of doing this. Drop me a line.