Created
October 22, 2012 15:07
-
-
Save malexandre/3931935 to your computer and use it in GitHub Desktop.
Rakefile for Jekyll with draft & publish management
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
desc "Given a title as an argument, create a new post file" | |
task :draft, :title do |t, args| | |
puts "Creating _drafts/#{args.title}" | |
filename = "#{args.title.gsub(/\s/, '_').downcase}.markdown" | |
path = File.join("_drafts", filename) | |
if File.exist? path; raise RuntimeError.new("Won't clobber #{path}"); end | |
File.open(path, 'w') do |file| | |
file.write <<-EOS | |
--- | |
layout: post | |
title: #{args.title} | |
--- | |
Content goes here | |
EOS | |
end | |
puts "Now open #{path} in an editor." | |
end | |
desc "Given a draft path as an argument, move it to '_posts' to publish it" | |
task :publish, :srcPath do |t, args| | |
now = DateTime::now().to_date() | |
filename = "#{now.strftime}-#{File.basename(args.srcPath)}" | |
destPath = File.join("_posts", filename) | |
if File.exist? destPath; raise RuntimeError.new("Won't clobber #{destPath}"); end | |
FileUtils.mv(args.srcPath, destPath) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by http://ilkka.github.com/blog/2010/12/08/rakefile_for_jekyll_site_management/
To use it, just put it in the root folder of your jekyll site, and call it via bash :
rake draft["Document title"]
rage publish["draft_path"]
The drafts will be created in the _drafts folder, be sure to create it before calling the Rakefile.