Skip to content

Instantly share code, notes, and snippets.

@omps
Created April 24, 2016 10:03
Show Gist options
  • Save omps/223f8c8e6a1d378f51d27f4d9b55b80c to your computer and use it in GitHub Desktop.
Save omps/223f8c8e6a1d378f51d27f4d9b55b80c to your computer and use it in GitHub Desktop.
rak new_post task
# 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, :tweet 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 => 'new-post', :tweet => '')
title = args.title
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')}"
post.puts "comments: true"
post.puts "categories: "
post.puts "---"
end
tweet = args.tweet
if not tweet == ''
# add to twitter status queue
puts 'Adding post to tweet queue, it will be tweeted after deploying.'
open('tweet_queue', 'a') do |file|
file.puts "#{tweet} - #{blog_url}#{Time.now.strftime('%Y/%m/%d')}/#{title.to_url}/"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment