-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
68 lines (63 loc) · 1.96 KB
/
Rakefile
File metadata and controls
68 lines (63 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require "rubygems"
require "stringex"
task :default => 'generate'
desc "Generate jekyll site"
task :generate do
puts "## Generating site with Jekyll"
sh "bundle exec jekyll build --safe"
end
desc "Launch preview environment"
task :preview do
sh "bundle exec jekyll serve --safe --watch"
end # task :preview
# usage rake new_post[my-new-post]
# or rake new_post['my new post']
# or rake new_post (prompts for title)
desc "Begin a new post"
task :new_post, :title do |t, args|
if args.title
title = args.title
else
title = get_stdin("Enter a title for your post: ")
end
mkdir_p "_posts"
filename = "_posts/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.md"
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 "external-url: "
post.puts "tags: "
post.puts "---"
end
end
# usage rake new_category[category-slug]
# or rake new_category['category name']
# or rake new_category (prompts for category name)
desc "Create a new category index"
task :new_category, :category do |t, args|
if args.category
category = args.category
else
category = get_stdin("Enter the category name: ")
end
mkdir_p "category"
filename = "category/#{category.to_url}.html"
if File.exist?(filename)
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
end
puts "Creating new category index: #{filename}"
open(filename, 'w') do |post|
post.puts "---"
post.puts "layout: category_index"
post.puts "title: \"#{category.gsub(/&/,'&')}\""
post.puts "tag: \"#{category.gsub(/&/,'&')}\""
post.puts "---"
end
end