forked from hepplerj/jasonheppler.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
80 lines (70 loc) · 2.05 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
# Jason Heppler
# Updated 2014-07-13
require "rake/clean"
require "stringex"
## -- Config -- ##
source_dir = "_site"
draft_dir = "_drafts"
posts_dir = "_posts"
server_port = "4000"
## -- Working with Jekyll -- ##
desc 'default: list available rake tasks'
task :default do
puts 'Try one of these specific tasks:'
sh 'rake --tasks --silent'
end
desc "Nuke and rebuild"
task :nuke do
sh 'rm -rf _site'
system "jekyll"
end
desc "Build the production version of the site"
task :build do
puts "\nBuilding the production version of the site ..."
ok_failed system "jekyll build"
end
desc "Preview the site with Jekyll"
task :preview do
puts "Previewing the site locally with Jekyll."
jekyllPid = Process.spawn("jekyll serve --watch")
trap("INT") {
[jekyllPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
exit 0
}
[jekyllPid].each { |pid| Process.wait(pid) }
end
desc "Give title as argument and create new post"
# usage rake write["Post Title Goes Here",category]
# category is optional
task :write do |t|
title = get_stdin("What is the title of the post? ")
link_check = get_stdin("Is this a link post? (y/n) ")
link_url = if link_check == "y" then get_stdin("Enter url: ") end
filename = "#{Time.now.strftime('%Y-%m-%d')}-#{title.gsub(/\s/, '-').downcase}.md"
path = File.join("_posts", filename)
if File.exist? path; raise RuntimeError.new("Won't clobber #{path}"); end
File.open(path, 'w') do |post|
post.puts "---"
post.puts "layout: post"
post.puts "title: \"#{title.gsub(/&/,'&')}\""
post.puts "date: #{Time.now.strftime('%Y-%m-%d %k:%M:%S')}"
if link_check == "y" then post.puts "external-url: #{link_url}" end
if link_check == "n" then post.puts "image: \n feature: \n thumb: " end
post.puts "categories: []"
post.puts "tags: []"
post.puts "---"
end
puts "Now opening #{path} in Sublime..."
system "subl #{path}"
end
def get_stdin(message)
print message
STDIN.gets.chomp
end
def ok_failed(condition)
if (condition)
puts "OK"
else
puts "FAILED"
end
end