Skip to content

Instantly share code, notes, and snippets.

@takaheraw
Created March 6, 2012 07:31
Show Gist options
  • Save takaheraw/1984676 to your computer and use it in GitHub Desktop.
Save takaheraw/1984676 to your computer and use it in GitHub Desktop.
# usage rake new_post[my-new-post] or rake new_post['my new post'] or rake new_post (defaults to "new-post")
desc "Begin a new post in #{source_dir}/#{posts_dir}"
task :new_post, :title do |t, args|
raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
mkdir_p "#{source_dir}/#{posts_dir}"
args.with_defaults(:title => "■")
title = args.title
index = 1
while File.exist?("#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{index}.#{new_post_ext}")
index += 1
end
filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{index}.#{new_post_ext}"
puts "Creating new post: #{filename}"
open(filename, 'w') do |post|
post.puts "---"
post.puts "layout: post"
post.puts "title: \"#{title.gsub(/&/,'&')}\""
post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M')}"
post.puts "comments: true"
post.puts "categories: "
post.puts "---"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment