...
|
...
|
@@ -274,25 +274,54 @@ task :set_root_dir, :dir do |t, args|
|
274
|
274
|
end
|
275
|
275
|
end
|
276
|
276
|
|
277
|
|
-desc "Setup _deploy folder and deploy branch"
|
278
|
|
-task :config_deploy, :branch do |t, args|
|
279
|
|
- puts "!! Please provide a deploy branch, eg. rake init_deploy[gh-pages] !!" unless args.branch
|
280
|
|
- puts "## Creating a clean #{args.branch} branch in ./#{deploy_dir} for Github pages deployment"
|
|
277
|
+desc "Set up _deploy folder and deploy branch for Github Pages deployment"
|
|
278
|
+task :setup_github do
|
|
279
|
+ repo_url = get_stdin("Enter the read/write url for your repository: ")
|
|
280
|
+ user = repo_url.match(/:([^\/]+)/)[1]
|
|
281
|
+ branch = (repo_url.match(/\/\w+.github.com/).nil?) ? 'gh-pages' : 'master'
|
|
282
|
+ project = (branch == 'gh-pages') ? repo_url.match(/\/([^\.]+)/)[1] : ''
|
|
283
|
+ unless `git remote -v`.match(/origin.+?octopress.git/).nil?
|
|
284
|
+ # If octopress is still the origin remote (from cloning) rename it to octopress
|
|
285
|
+ system "git remote rename origin octopress"
|
|
286
|
+ if branch == 'master'
|
|
287
|
+ # If this is a user/organization pages repository, add the correct origin remote
|
|
288
|
+ # and checkout the source branch for committing changes to the blog source.
|
|
289
|
+ system "git remote add origin #{repo_url}"
|
|
290
|
+ puts "Added remote #{repo_url} as origin"
|
|
291
|
+ system "git config branch.master.remote origin"
|
|
292
|
+ puts "Set origin as default remote"
|
|
293
|
+ system "git branch -m master source"
|
|
294
|
+ puts "Master branch renamed to 'source' for committing your blog source files"
|
|
295
|
+ else
|
|
296
|
+ unless !public_dir.match("#{project}").nil?
|
|
297
|
+ system "rake set_root_dir[#{project}]"
|
|
298
|
+ end
|
|
299
|
+ end
|
|
300
|
+ end
|
|
301
|
+ url = "http://#{user}.github.com"
|
|
302
|
+ url += "/#{project}" unless project == ''
|
|
303
|
+ jekyll_config = IO.read('_config.yml')
|
|
304
|
+ jekyll_config.sub!(/^url:.*$/, "url: #{url}")
|
|
305
|
+ File.open('_config.yml', 'w') do |f|
|
|
306
|
+ f.write jekyll_config
|
|
307
|
+ end
|
|
308
|
+ rm_rf deploy_dir
|
|
309
|
+ mkdir deploy_dir
|
281
|
310
|
cd "#{deploy_dir}" do
|
282
|
|
- system "git symbolic-ref HEAD refs/heads/#{args.branch}"
|
283
|
|
- system "rm .git/index"
|
284
|
|
- system "git clean -fdx"
|
|
311
|
+ system "git init"
|
285
|
312
|
system "echo 'My Octopress Page is coming soon …' > index.html"
|
286
|
313
|
system "git add ."
|
287
|
314
|
system "git commit -m \"Octopress init\""
|
|
315
|
+ system "git branch -m gh-pages" unless branch == 'master'
|
|
316
|
+ system "git remote add origin #{repo_url}"
|
288
|
317
|
rakefile = IO.read(__FILE__)
|
289
|
|
- rakefile.sub!(/deploy_branch(\s*)=(\s*)(["'])[\w-]*["']/, "deploy_branch\\1=\\2\\3#{args.branch}\\3")
|
|
318
|
+ rakefile.sub!(/deploy_branch(\s*)=(\s*)(["'])[\w-]*["']/, "deploy_branch\\1=\\2\\3#{branch}\\3")
|
290
|
319
|
rakefile.sub!(/deploy_default(\s*)=(\s*)(["'])[\w-]*["']/, "deploy_default\\1=\\2\\3push\\3")
|
291
|
320
|
File.open(__FILE__, 'w') do |f|
|
292
|
321
|
f.write rakefile
|
293
|
322
|
end
|
294
|
323
|
end
|
295
|
|
- puts "## Deployment configured. Now you can deploy to the #{args.branch} branch with `rake deploy` ##"
|
|
324
|
+ puts "\n---\n## Now you can deploy to #{url} with `rake deploy` ##"
|
296
|
325
|
end
|
297
|
326
|
|
298
|
327
|
def ok_failed(condition)
|