Combining Matt Gemmell's Staging Script and Jekyll-Post-Link

Last week, Matt Gemmell released a pretty handy staging script for Jekyll.1 This temporarily removes all your posts from your site and copies a draft into _posts. This way, building your Jekyll site with your new draft post is way faster than your regular builds with all your content.

Unfortunately, this does not work when you’re using the jekyll-post-link in one of your pages. (Yes, I mean pages, not posts.) The build process for your staged website will fail with an error like this:

Liquid Exception: Could not find post "2015-02-05-foo bar" in tag 'post_link'. Make sure the post exists and the name and date is correct. in

This morning I talked to Matt about this over on Twitter. He mentioned, that it should be fairly easy to make it work. And he was right. I forked the jekyll-post-link project and made it check if we’re in staging mode before failing on us when a “broken” link appears.

Whenever it finds a post link now, it replaces it with a dummy link. Next time you do the actual build outside of staging mode everything will be back to normal.

You can find my version on GitHub. Hope this helps. If you have any questions or suggestions feel free to get in touch.

Thanks to Matt and Liam for their great plugins!

  1. As of today, it’s also available as a Ruby gem with multi-site support. ↩︎