-
Notifications
You must be signed in to change notification settings - Fork 8
/
Rakefile
executable file
·76 lines (66 loc) · 1.7 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
task :default => :build
desc 'Clean up generated site'
task :clean do
cleanup
end
desc 'Test site output for Liquid template errors'
task :test => :build do
errors = `grep --exclude Rakefile -R 'Liquid error:' _site`
if errors.nil? || errors.empty?
puts "No errors"
else
puts "Errors:"
puts errors.inspect
exit 1
end
end
desc 'Build site with Jekyll'
task :build => :clean do
submodule('update')
jekyll('build')
end
desc 'Start server with --auto'
task :server => :clean do
jekyll('serve --watch --config _config.yml,_config_local.yml')
end
desc 'Build and deploy'
task :deploy => :build do
user = 'kemayo'
host = 'kemayo.webfactional.com'
directory = '~/webapps/davidlynch'
sh "rsync -rtzh --progress --delete _site/ #{user}@#{host}:#{directory}"
end
desc 'Make a new post'
task :post, [:name] do |t, args|
if args.name then
template(args.name)
else
puts "Name required"
end
end
def template(name)
t = Time.now
contents = "" # otherwise using it below will be badly scoped
File.open("_posts/yyyy-mm-dd-template.markdown", "rb") do |f|
contents = f.read
end
contents = contents.sub("%date%", t.strftime("%Y-%m-%d %H:%M:%S %z")).sub("%title%", name)
filename = "_posts/" + t.strftime("%Y-%m-%d-") + name.downcase.gsub( /[^a-zA-Z0-9_\.]/, '-') + '.markdown'
if File.exists? filename then
puts "Post already exists: #{filename}"
return
end
File.open(filename, "wb") do |f|
f.write contents
end
puts "created #{filename}"
end
def cleanup
sh 'rm -rf _site'
end
def jekyll(opts = '')
sh 'jekyll ' + opts
end
def submodule(opts = '')
sh 'git submodule ' + opts
end