Skip to content

Commit 6d0e38b

Browse files
committed
Add rake task to create pages
Usage: rake page name='about.md'
1 parent f52ff5a commit 6d0e38b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Rakefile

+24
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@ task :post do
3232
end
3333
end # task :post
3434

35+
# Usage: rake page name="about.html"
36+
# You can also specify a sub-directory path.
37+
# If you don't specify a file extention we create an index.html at the path specified
38+
desc "Create a new page."
39+
task :page do
40+
name = ENV["name"] || "new-page.md"
41+
filename = File.join(SOURCE, "#{name}")
42+
filename = File.join(filename, "index.html") if File.extname(filename) == ""
43+
title = File.basename(filename, File.extname(filename)).gsub(/[\W\_]/, " ").gsub(/\b\w/){$&.upcase}
44+
if File.exist?(filename)
45+
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
46+
end
47+
48+
mkdir_p File.dirname(filename)
49+
puts "Creating new page: #{filename}"
50+
open(filename, 'w') do |post|
51+
post.puts "---"
52+
post.puts "layout: page"
53+
post.puts "title: \"#{title}\""
54+
post.puts "---"
55+
post.puts "{% include JB/setup %}"
56+
end
57+
end # task :page
58+
3559
desc "Switch between Jekyll-bootstrap themes."
3660
task :switch_theme, :theme do |t, args|
3761
theme_path = File.join(CONFIG['themes'], args.theme)

0 commit comments

Comments
 (0)