Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding the new_post task, with bugs fixed which were pointed out by @…

  • Loading branch information...
commit 6ee3125c179e2f610b039b3ace9a3836a998a4ee 1 parent f3f08f9
@pradeep1288 pradeep1288 authored
Showing with 43 additions and 0 deletions.
  1. +43 −0 Rakefile
View
43 Rakefile
@@ -1,6 +1,49 @@
require "rubygems"
require 'rake'
+## -- Misc Configs --##
+jekyll_dir = "."
+posts_dir = "_posts"
+new_post_ext = "md"
+
+# 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 #{jekyll_dir}/#{posts_dir}"
+task :new_post, :title do |t, args|
+ raise "### Cannot locate the #{posts_dir}." unless File.directory?(posts_dir)
+ mkdir_p "#{jekyll_dir}/#{posts_dir}"
+ args.with_defaults(:title => 'new-post')
+ slug = args.title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
+ title = args.title.gsub(/-/,' ')
+ filename = "#{jekyll_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{slug}.#{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}\""
+ post.puts "comments: true"
+ post.puts "category: "
+ post.puts "tags: []"
+ post.puts "---"
+ end
+end
+
+def ask(message, valid_options)
+ if valid_options
+ answer = get_stdin("#{message} #{valid_options.to_s.gsub(/"/, '').gsub(/, /,'/')} ") while !valid_options.include?(answer)
+ else
+ answer = get_stdin(message)
+ end
+ answer
+end
+
+def get_stdin(message)
+ print message
+ STDIN.gets.chomp
+end
+
desc "Switch between Jekyll-bootstrap themes."
task :switch_theme, :theme do |t, args|
theme_path = File.join(File.dirname(__FILE__), "_includes", "themes", args.theme)

0 comments on commit 6ee3125

Please sign in to comment.
Something went wrong with that request. Please try again.