-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrakefile
106 lines (80 loc) · 3.25 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
require 'time'
task :cleanRemote do
sh 'find . -type f -name \'*_Conflicted_by_Write_*.*\' -delete'
sh 'rm -rf ~/brunow.org/output'
end
task :buildRemote => [:cleanRemote] do
sh 'magneto --config ~/brunow.org/config.yaml --source ~/brunow.org/ --output ~/brunow.org/output/'
end
task :deployRemote => [:buildRemote] do
sh 'rsync -avz ~/brunow.org/output/ [email protected]:/var/www/brunow.org/public_html/'
end
task :buildAutomatedRemote do
sh 'magneto --config /users/davidhbrunow/dropbox/websites/brunow.org/config.yaml --source /users/davidhbrunow/dropbox/websites/brunow.org/ --output /users/davidhbrunow/dropbox/websites/brunow.org/output/'
end
task :deployAutomatedRemote => [:buildAutomatedRemote] do
sh 'rsync -avz /users/davidhbrunow/brunow.org/output/ [email protected]:public/brunow.org/public/'
end
task :clean do
sh 'rm -rf ~/Dropbox/websites/brunow.org/output'
end
task :build do
sh 'magneto --config ./config.yaml --source . --output ./public/'
end
task :deploy => [:build] do
sh 'cp -a ~/Dropbox/websites/brunow.org/output/. ~/public/brunow.org/public/'
end
task :stage => [:clean] do
sh 'cat config.yaml | sed \'s/^\(base_url:\).*$/\1 http:\/\/stage.brunow.org/;s/^\(cdn_url:\).*$/\1 ""/;s/^\(google_analytics_account:\).*$/\1 ""/\' >stage_config.yaml && time magneto --config stage_config.yaml && rsync -cavzh --delete --stats --progress output/ stage.brunow.org:stage.brunow.org && open http://stage.brunow.org/'
end
task :mamp => [:clean] do
sh 'cat config.yaml | sed \'s/^\(base_url:\).*$/\1 http:\/\/localhost/;s/^\(cdn_url:\).*$/\1 ""/;s/^\(google_analytics_account:\).*$/\1 ""/\' >mamp_config.yaml && time magneto --config mamp_config.yaml && rsync -cavzh --delete --stats --progress output/ /Applications/MAMP/htdocs/ && open http://localhost/'
end
task :draft do
print "Title for post? "
title = STDIN.gets.chomp.strip
slug = title_to_slug(title)
raise "Empty title" if slug.empty?
draft = "drafts/#{slug}.md"
raise "#{draft} exists" if File.exists?(draft)
mkdir_p "drafts"
open(draft, 'w') do |f|
f.write <<EOF
---
published: #{Time.now.xmlschema}
title: #{title}
---
EOF
end
sh "open #{draft}"
end
task :post do
drafts = Dir["drafts/*"]
raise "No drafts to post" if drafts.empty?
drafts.each_with_index { |f, i| puts "#{i + 1}: #{f}" }
print "Which draft? "
index = STDIN.gets.chomp.to_i
raise "Invalid index" if index < 1 || index > drafts.count
draft = drafts[index - 1]
raise "#{draft} does not exist" unless File.exists?(draft)
content = File.read(draft)
raise "#{draft} missing title" unless content =~ /^---\s*\n.*?\n?title:\s?(.*)\s*\n.*?\n?^---\s*$\n?/m
title = $1
slug = title_to_slug(title)
raise "#{draft} empty title" if slug.empty?
timestamp = Time.now
post = "items/#{timestamp.strftime("%Y/%m-%d")}-#{slug}.md"
raise "#{post} exists" if File.exists?(post)
mkdir_p File.dirname(post)
content.sub!(/^published:\s?.*$/, "published: #{timestamp.xmlschema}")
open(post, 'w') do |f|
f.print content
end
raise "#{post} does not exist" unless File.exists?(post)
rm draft
File.utime(timestamp, timestamp, post)
puts post
end
def title_to_slug(title)
title.downcase.gsub(/[_\s]+/, '-').gsub(/[^-\w]/, '').gsub(/-+/, '-').sub(/^-/, '').sub(/-$/, '')
end