-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathRakefile
More file actions
executable file
·81 lines (71 loc) · 1.86 KB
/
Copy pathRakefile
File metadata and controls
executable file
·81 lines (71 loc) · 1.86 KB
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
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 = 'davidlynch.org'
directory = '/var/www/davidlynch.org/'
sh "rsync -rtOzh --progress --delete --exclude=/.well-known _site/ #{user}@#{host}:#{directory}"
end
desc 'Make a new post'
task :post, [:name, :date] do |t, args|
if args.name then
template(args.name, args.date)
else
puts "Name required"
end
end
def template(name, date)
require 'date'
if date.is_a?(String)
date = DateTime.parse(date)
else
date = DateTime.now
end
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%", date.strftime("%Y-%m-%d %H:%M:%S %z")).sub("%title%", name)
filename = "_posts/" + date.strftime("%Y-%m-%d-") + name.downcase.gsub( /[^a-zA-Z0-9_\.]/, '-') + '.markdown'
if File.exist? 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 'bundle exec jekyll ' + opts
end
def submodule(opts = '')
sh 'git submodule ' + opts
end