-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrakefile
More file actions
30 lines (26 loc) · 729 Bytes
/
rakefile
File metadata and controls
30 lines (26 loc) · 729 Bytes
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
posts_dir = "_posts"
posts_ext = "markdown"
posts_author = "YorkYan"
task :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_dir}"
filename = "#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title}.#{posts_ext}"
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:%S')}"
post.puts "author: \"#{posts_author}\""
post.puts "categories: "
post.puts "---"
end
end
def get_stdin(message)
print message
STDIN.gets.chomp
end