-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakeold
236 lines (196 loc) · 5.6 KB
/
Rakeold
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# Magnus Eriksson
# Modified from Jason Heppler
# Modified from Jeff McFadden:
# http://jeffmcfadden.com/blog/2011/04/13/rsync-your-jekyll/
# Requirements
require 'rake' # For the rake tasks
require 'yaml' # For reading the configuration file
require 'fileutils' # For creating recursive directories
# Load the configuration file
config = YAML.load_file("_config.yml")
# Set "rake watch" as default task
task :default => :build
## -- Config -- ##
source_dir = "_site"
draft_dir = "_drafts"
posts_dir = "_posts"
stash_dir = "_stash"
server_port = "4000"
##############
# Deploying #
##############
## Push
desc 'push master to blay.se and github via git'
task :push, :message do |t, args|
message = args[:message]
branch = config["git"]["branch"]
if message.nil? or message.empty?
message = "auto"
end
if branch.nil? or branch.empty?
raise "Please add a branch."
else
puts 'PUSHING MASTER TO BLAY AND GITHUB'
system "git checkout #{branch}"
system "git add ."
system "git commit -m \"#{message}\""
system "git push origin #{branch}"
system "git push github #{branch}"
puts 'Done!'
end
end
desc 'push dev to blay.se and github via git'
task :pushdev, :message do |t, args|
message = args[:message]
branch = config["git"]["branch_dev"]
if message.nil? or message.empty?
message = "auto"
end
if branch.nil? or branch.empty?
raise "Please add a branch."
else
puts 'PUSHING DEV TO BLAY AND GITHUB'
system "git checkout #{branch}"
system "git add ."
system "git commit -m \"#{message}\""
system "git push origin #{branch}"
system "git push github #{branch}"
puts 'Done!'
end
end
## Transfer
desc "Transfer the site to the remote server"
task :transfer do
command = config["transfer"]["command"]
source = config["transfer"]["source"]
destination = config["transfer"]["destination"]
settings = config["transfer"]["settings"]
if command == "rsync"
Rake::Task[:build].invoke
system "rsync #{settings} #{source} #{destination}"
puts "Your site was transfered."
else
raise "#{command} isn't a valid file transfer command."
end
end
desc "Transfer the dev site to the remote server"
task :transferdev do
command = config["transfer"]["command"]
source = config["transfer"]["source"]
destination = config["transfer"]["destination_dev"]
settings = config["transfer"]["settings"]
if command == "rsync"
Rake::Task[:build].invoke
system "rsync #{settings} #{source} #{destination}"
puts "Your site was transfered."
else
raise "#{command} isn't a valid file transfer command."
end
end
#######
# All #
#######
desc 'Build, Push, Transfer'
task :all => ["push", "transfer"]
desc 'Build, Push, Transfer Dev'
task :all => ["pushdev", "transferdev"]
#######################
# Working with Jekyll #
#######################
desc 'default: list available rake tasks'
task :default do
puts 'Try one of these specific tasks:'
sh 'rake --tasks --silent'
end
# rake build
desc "Generate the site (no server)"
task :build do
system "jekyll --no-server"
end
desc "nuke and rebuild"
task :nuke do
sh 'rm -rf _site'
system "jekyll"
end
# rake watch
# rake watch[number]
desc "Generate and watch the site (with an optional post limit)"
task :watch, :number do |t, args|
number = args[:number]
if number.nil? or number.empty?
system "jekyll --auto --server"
else
system "jekyll --auto --server --limit_posts=#{number}"
end
end
# rake preview
desc "Launch a preview of the site in the browser"
task :preview do
require 'Launchy'
puts "Launching browser for preview..."
sleep 2
Thread.new do
Launchy.open("http://localhost:4000/")
end
Rake::Task[:watch].invoke
end
#########
# Posts #
#########
## Creating Posts
desc "give title as argument and create new post"
# usage rake write["Post Title Goes Here",category]
# category is optional
task :write, [:title, :category] do |t, args|
filename = "#{Time.now.strftime('%Y-%m-%d')}-#{args.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 |file|
file.write <<-EOS
---
layout: post
title: #{args.title}
date: #{Time.now.strftime('%Y-%m-%d %k:%M:%S')}
tags:
category: #{args.category}
---
EOS
end
puts "Now opening #{path} in subl..."
system "subl #{path}"
end
desc "give title as argument for draft post"
# usage rake draft["Post Title Goes Here",category]
# category is optional
task :draft, [:title, :category] do |t, args|
filename = "#{Time.now.strftime('%Y-%m-d')}-#{args.title.gsub(/\s/, '-').downcase}.md"
path = File.join("_drafts", filename)
if File.exist? path; raise RuntimeError.new("Won't clobber #{path}"); end
File.open(path, 'w') do |file|
file.write <<-EOS
---
layout: post
title: #{args.title}
date: #{Time.now.strftime('%Y-%m-d %k:%M:%S')}
tags:
-
category: #{args.category}
---
EOS
end
puts "Now opening #{path} in subl..."
system "subl #{path}"
end
## Isolating and Integrating
desc "Move all other posts than the one currently being worked on to a temporary stash location (stash) so regenerating the site happens much quicker."
task :isolate, :filename do |t, args|
stash_dir = "#{stash_dir}"
FileUtils.mkdir(stash_dir) unless File.exist?(stash_dir)
Dir.glob("#{posts_dir}/*.*") do |post|
FileUtils.mv post, stash_dir unless post.include?(args.filename)
end
end
desc "Move all stashed posts back into the posts directory, ready for site generation."
task :integrate do
FileUtils.mv Dir.glob("#{stash_dir}/*.*"), "#{posts_dir}/"
end