I have a couple blogs that run off of Jekyll and I wanted to be able to quickly fire off a post from another workstation. The work-flow I wanted was something like this:

  1. Write a markdown-format post on another computer.
  2. Save it to a google-drive folder synced with my main machine.
  3. Cron on my main computer runs a sorting script every 15 minutes
  4. The sorting script looks at the blog: YAML frontmatter and moves the post to the correct directory

As it turns out, there’s a nice library for reading YAML frontmatter (called python-frontmatter) that makes this pretty easy.

Before working with Jekyll, I’d never heard of YAML. It stands for YAML Ain’t Markup Language. They call it a “data serialization standard”, but I have no idea what that means.

Here’s the program that I have cron run every 15 minutes:

#!/usr/bin/python
import frontmatter, shutil, os
inbox = "/{path}/jekyllInbox/"
blogs = {}
blogs['blog1'] = "/{blog1 path}/_posts"
blogs['blog2'] = "/{blog2 path}/_posts"
#add more blogs as needed

def findBlog(p):
    post = frontmatter.load(p)
    if post['blog']:
        return post['blog']
    else:
        return False

def movePost(p):
    blog = findBlog(p)
    if blog and blog in blogs:
        shutil.move(p, blogs[blog])
        if os.path.isfile(p): #file was copied; not moved
            os.remove(p)

for f in os.listdir(inbox):
    if f.endswith(".md"):
        fpath = inbox + f
        movePost(fpath)

The frontmatter for your post just needs to indicate which blog it goes to:

---
blog: blog1
title: Dummy Post
categories: examples
---

Hello World