Skip to content

Instantly share code, notes, and snippets.

@malexandre
Created October 22, 2012 15:07
Show Gist options
  • Save malexandre/3931935 to your computer and use it in GitHub Desktop.
Save malexandre/3931935 to your computer and use it in GitHub Desktop.
Rakefile for Jekyll with draft & publish management
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
@malexandre
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment