forked from barryclark/jekyll-now
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
70 lines (60 loc) · 2.14 KB
/
Rakefile
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
69
require "rubygems"
require "bundler/setup"
require "stringex"
# http://culttt.com/2015/08/05/understanding-and-using-ruby-rake/
posts_dir = "_posts"
new_post_ext = "md"
desc "Display rake tasks"
task :help do |t, args|
Process.wait(Process.spawn("bash -c 'rake --tasks | grep -v rake\\ help'"))
end
desc "Preview page"
task :view do |t, args|
puts "[INFO] Previewing and watching using jekyll serve"
jekyllPid = Process.spawn("jekyll serve")
trap("INT") {
[jekyllPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
puts "[INFO] Trapped CTRL+C, killed children, exited properly"
exit 0
}
[jekyllPid].each { |pid| Process.wait(pid) }
end
desc "Preview page including drafts"
task :write do |t, args|
puts "[INFO] Previewing and watching using jekyll serve --drafts"
jekyllPid = Process.spawn("jekyll serve --drafts")
trap("INT") {
[jekyllPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
puts "[INFO] Trapped CTRL+C, killed children, exited properly"
exit 0
}
[jekyllPid].each { |pid| Process.wait(pid) }
end
# usage rake new_post[my-new-post] or rake new_post['my new post'] or rake new_post (defaults to "new-post")
desc "Publish a draft (move from _drafts to _posts)(unfinished)"
task :publish do |t, args|
puts "Hello world"
end
# usage rake new_post[my-new-post] or rake new_post['my new post'] or rake new_post (defaults to "new-post")
desc "Begin a new post in ./#{posts_dir} (unfinished)"
task :post, :title do |t, args|
if args.title
title = args.title
else
title = get_stdin("Enter a title for your post: ")
end
filename = "./#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}"
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:%S %z')}"
# post.puts "comments: true"
# post.puts "categories: "
# post.puts "---"
#end
end