Rake Publish
Rake Publish
June 23, 2014
Note
2025 Update. This blog is no longer Octoblog, but the content is still valid.
Octoblog (the engine behind this blog) uses Jekyll. As such, it also supports the publish
flag. I a previous post I detailed how I added this feature back to Octopress. Here I will show you a little rake task to easily publish an unpublished post.
Requirements
For a post to be published I wanted a few things to happen:
published: true
was set in the YAML front-matterdate: <todays date>
was set in the YAML front-matter- The file was moved to today.
Here is what I came up with for my Rakefile
.
|
|
- Line 6: I take a argument and get a list of files matching the pattern
- Line 7 & 8: I found it was too easy to screw up a pattern and publish too few or too many posts. For that reason I am explicit about the failure.
- Line 15: Calculates its name for today.
- Line 16 & 37: Generate a temp file to write to. I found that bad things happened if you published a post that you wrote the same day. Solution was to write to a temp file and then move the temp file later.
- Line 19 && 22: An inelegant solution to isolating scanning to only the YAML front-matter.
- Line 28 & 29: Update the YAML front-matter.