A Jekyll Plugin To Buffer Your Posts

I'd say one of my least favorite parts of writing articles, is the tedious and necessary task of sharing those articles on social media sites. I just feel a little dirty doing the self-promotion, but every so often, someone finds an article that way, and finds it valuable, so I continued it until recently.

Now that I'm publishing posts from a queue, the last thing I want to do is to have to remember what's being published, and to tweet about it. It would would be better to have something that shared an update on all of my social networks when the post is published.

Well, that's the plugin I've built.

Buffer to the Rescue

Buffer is pretty great. You hook up Twitter, Facebook, LinkedIn and App.net (what is this? does anyone use it?) and then you can make one update that goes to all 4 services. Additionally, Buffer has helpful ruby library that makes interfacing problematically a snap.

Here, is the original code of the plugin; you must excuse the obvious hacky-ness, it is truly a work in progress:

require 'buff'

class Buffer < Jekyll::Generator
  def generate(site)
    post = most_recent_post(site)
    post_date = post.date.strftime('%Y-%m-%d')
    today_date = Date.today.strftime('%Y-%m-%d')
    if post_date == today_date
      message = generate_message(post)
      log "Buffer message: \"#{message}\""
      buffer(message, site)
      log 'Not sending latest promotion because older than today...'


  def generate_message(post)
    promotion_message = post.data['promotion'] || ''
    "#{promotion_message} #{post.location_on_server}"

  def most_recent_post(site)
    site.posts.reduce do |memo, post|
      memo.date > post.date ? memo : post

  def buffer(message, site)
    access_token = ENV['BUFFER_ACCESS_TOKEN'] || site.config['buffer_access_token']
    fail ArgumentError, 'No Buffer access token!' unless access_token
    client = Buff::Client.new(access_token)
    content = { body: { text: message, top: true, shorten: true,
                        profile_ids: site.config['buffer_profiles'] } }
    if site.config['send_to_buffer']
      response = client.create_update(content)
      log("Buffer API Response: #{response.inspect}")
      log 'Not sending latest post promotion to Buffer...'

  def log(message)
    puts "\n\n#{message}\n\n"

The plugin requires that you:

  1. Register your blog as a Buffer application to generate an access token.
  2. Add the promotion field to your YAML front matter for all new posts with a short message, basically what will become your status update.
  3. Provide the access token as either an environment variable (BUFFER_ACCESS_TOKEN) on your server or in the configuration file (buffer_access_token).
  4. Provide an array of buffer_profiles in your configuration file. These are the ID's of each of your social accounts.

The quickest way to get your profile information is to send a GET request to the following end point, replacing the access token with your own:


Now It's Automatic

With this plugin, every time the site is generated, it will grab the promotion message out of the latest post, append the URL of the post onto it, and create a Buffer update for all of my social profiles, putting it at the top of whatever might be in the Buffer already. Also, the URL will be shortened by the Buffer shortening service.

If I regenerate the site when the latest post's date is not "today", it will not send an update, allowing me to refresh the build outside of when I might ordinarily publish an article.

This is a pretty good start, and with this plugin, my blogging process has been reduced to simply: Write article, proofread, commit, push. Everything else is automatic.

If you enjoyed reading this or learned something, please consider sharing via , , or . Thanks!