BXG Blog

Scheduled Posts with Pelican

I’ve been enjoying the benefits of using Pelican for this blog for about a year now. Aside from the minimal resource usage and dead-simple webserver configuration, it has been fantastic to not have security updates to worry about

However, one feature that is missing compared to the typical database-driven blogs is the ability to schedule a article for the future. Since Pelican isn’t active unless you actually run it, it isn’t completely obvious how to do it.

Since Pelican is a command-line app, this is the sort of thing where cron usually saves the day. If I run Pelican from a cron once (or several) times a day, I could hypothetically drop new content in at the right time and have it show up by itself. But how to drop content in? Is it turtles all the way down?

Well, Pelican has a concept of draft articles. These articles get processed like published articles, but their output goes into a separate drafts directory that isn’t linked from the main site. If we can put the content in the right place but get the articles to stay in the draft state until the correct time, we’ll have the problem solved. Since the draft status comes from the Status field, this seems to be closer to a solution than dropping in files. The Date field tells us when the article is supposed to be published, so how about this plan:

  1. Run pelican from cron on a regular schedule.
  2. If the article’s date is in the future, pretend its status is draft.

I started poking through the source code to add this hack, and I discovered a setting called WITH_FUTURE_DATES. Guess what WITH_FUTURE_DATES does when set to False? It forces articles with dates in the future to be treated as drafts. Perfect! Clearly, somebody else has already had a similar problem to solve. So here’s the new plan:

  1. Set WITH_FUTURE_DATES to False in my config.
  2. Run pelican from cron on a regular schedule.
  3. Write articles and set their Date field to the date when the article should actually be published.
  4. Explicitly set the Status field to “draft” if an article isn’t ready yet (which is probably a good idea anyway).

If this post shows up at 6AM on 2016-02-29, we’ll know it works.