Permalink
Browse files

Add rake task to create pages

Usage: rake page name='about.md'
  • Loading branch information...
1 parent f52ff5a commit 6d0e38b3657f2631f977c6c748698e20ae939bb3 @plusjade plusjade committed Jan 23, 2012
Showing with 24 additions and 0 deletions.
  1. +24 −0 Rakefile
View
@@ -32,6 +32,30 @@ task :post do
end
end # task :post
+# Usage: rake page name="about.html"
+# You can also specify a sub-directory path.
+# If you don't specify a file extention we create an index.html at the path specified
+desc "Create a new page."
+task :page do
+ name = ENV["name"] || "new-page.md"
+ filename = File.join(SOURCE, "#{name}")
+ filename = File.join(filename, "index.html") if File.extname(filename) == ""
+ title = File.basename(filename, File.extname(filename)).gsub(/[\W\_]/, " ").gsub(/\b\w/){$&.upcase}
+ if File.exist?(filename)
+ abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
+ end
+
+ mkdir_p File.dirname(filename)
+ puts "Creating new page: #{filename}"
+ open(filename, 'w') do |post|
+ post.puts "---"
+ post.puts "layout: page"
+ post.puts "title: \"#{title}\""
+ post.puts "---"
+ post.puts "{% include JB/setup %}"
+ end
+end # task :page
+
desc "Switch between Jekyll-bootstrap themes."
task :switch_theme, :theme do |t, args|
theme_path = File.join(CONFIG['themes'], args.theme)

0 comments on commit 6d0e38b

Please sign in to comment.