Skip to content

Commit

Permalink
Add rake task to create pages
Browse files Browse the repository at this point in the history
Usage: rake page name='about.md'
  • Loading branch information
plusjade committed Jan 23, 2012
1 parent f52ff5a commit 6d0e38b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Rakefile
Expand Up @@ -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)
Expand Down

0 comments on commit 6d0e38b

Please sign in to comment.