devroom.io/Rakefile
2014-04-04 15:14:42 +02:00

28 lines
771 B
Ruby

require 'stringex'
desc "Create a new post"
task :new_post, :title do |t, args|
mkdir_p './content/posts'
args.with_defaults(:title => 'New Post')
title = args.title
filename = "./content/posts/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.md"
if File.exist?(filename)
abort('rake aborted!') if ask("#{filename} already exists. Want to overwrite?", ['y','n']) == 'n'
end
puts "Creating new post: #{filename}"
open(filename, 'w') do |post|
post.puts '---'
post.puts "title: \"#{title}\""
post.puts "created_at: #{Time.now}"
post.puts 'kind: article'
post.puts 'published: false'
post.puts 'tags:'
post.puts ' - tag1'
post.puts 'summary: |'
post.puts " Summary for #{title}"
post.puts "---\n\n"
end
end