-
Notifications
You must be signed in to change notification settings - Fork 46
/
Rakefile
147 lines (129 loc) · 4.64 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
require "stringex"
# This rakefile will provide rake tasks to make it easier to manage a Jekyll blog
## -- Misc Configs -- ##
posts_dir = "_posts" # directory for blog files
new_post_ext = "md" # default new post file extension when using the new_post task
desc "Generate the website using Jekyll"
task :generate do
puts "## Generating site with Jekyll"
system "jekyll build"
end
desc "Preview the generated website in a browser and keep watching for changes"
task :preview do
puts "## Serving the generated site to localhost:4000 and watching for changes"
jekyllPid = Process.spawn("jekyll serve")
trap("INT") {
Process.kill(9, jekyllPid) rescue Errno::ESRCH
exit 0
}
Process.wait(jekyllPid)
end
desc "Begin a new blog post in /_posts. Use as rake new_news_item[title,author,file-extension]. In absence of any of those, the values will be asked for interactively."
task :new_blog_post, [:title, :author, :extension] do |t, args|
if args.title
title = args.title
else
puts("Enter a title for your post: ")
title = STDIN.gets.chomp
end
if args.author
author = args.author
else
puts("Enter your GitHub username: ")
author = STDIN.gets.chomp
end
if args.extension
new_post_ext = args.extension
else
puts("Enter the file extension you want to use: ")
new_post_ext = STDIN.gets.chomp
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: default"
post.puts "title: \"#{title.gsub(/&/,'&')}\""
post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}"
post.puts "categories: [blog]"
post.puts "author: #{author}"
post.puts "download: true"
post.puts "---"
end
end
desc "Begin a new news post in /_posts. Use as rake new_news_item[title,author,file-extension]. In absence of any of those, the values will be asked for interactively."
task :new_news_item, [:title, :author, :extension] do |t, args|
if args.title
title = args.title
else
puts("Enter a title for your post: ")
title = STDIN.gets.chomp
end
if args.author
author = args.author
else
puts("Enter your GitHub username: ")
author = STDIN.gets.chomp
end
if args.extension
new_post_ext = args.extension
else
puts("Enter the file extension you want to use: ")
new_post_ext = STDIN.gets.chomp
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: default"
post.puts "title: \"#{title.gsub(/&/,'&')}\""
post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}"
post.puts "categories: [news]"
post.puts "author: #{author}"
post.puts "download: true"
post.puts "---"
end
end
desc "Begin a new release post in /_posts. Use as rake new_release[version-number,author,file-extension]. In absence of any of those, the values will be asked for interactively. The fully formed title becomes 'Open Live Writer version-number is now available!'."
task :new_release, [:version, :author, :extension] do |t, args|
if args.version
version = args.version
else
puts("Enter the version number (The fully formed title becomes 'Open Live Writer version-number is now available!'): ")
version = STDIN.gets.chomp
end
title = "Open Live Writer #{version} is now available!"
if args.author
author = args.author
else
puts("Enter your GitHub username: ")
author = STDIN.gets.chomp
end
if args.extension
new_post_ext = args.extension
else
puts("Enter the file extension you want to use: ")
new_post_ext = STDIN.gets.chomp
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: default"
post.puts "title: \"#{title.gsub(/&/,'&')}\""
post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}"
post.puts "categories: [news, release]"
post.puts "author: #{author}"
post.puts "download: true"
post.puts "---"
end
end