require "stringex" def jekyll(opts="", path="") sh "rm -rf _site" sh "mkdir _site" sh path + "jekyll " + opts end desc "Build site using Jekyll" task :build do jekyll end desc "Serve on Localhost with port 4000" task :default do jekyll "--server --auto " end namespace :posts do task :new, :title do |t, args| title = args.title filename = "_posts/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.mkd" 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 end end