Skip to content

Instantly share code, notes, and snippets.

@leigh-johnson
Last active August 29, 2015 14:05
Show Gist options
  • Save leigh-johnson/597685ce6d04ee04eb7e to your computer and use it in GitHub Desktop.
Save leigh-johnson/597685ce6d04ee04eb7e to your computer and use it in GitHub Desktop.
Add HPSTR fields to rake new_post()
desc "Begin a new post in #{source_dir}/#{posts_dir}"
task :new_post, :title do |t, args|
if args.title
title = args.title
else
title = get_stdin("Enter a title for your post: ")
end
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}"
filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}"
if File.exist?(filename)
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
end
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:%S %z')}"
post.puts "comments: true"
post.puts "categories: "
post.puts "image:"
post.puts "feature:"
post.puts "image: "
posts.puts "thumb:"
post.puts "share: true"
post.puts "---"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment