forked from nicangeli/short_format_notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
72 lines (66 loc) · 1.99 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
desc "Commit the local site to the gh-pages branch and publish to GitHub Pages"
task :publish => ["publish:clean_gh_pages",
"publish:generate_site",
"publish:copy_site",
"publish:commit_and_push"]
namespace :publish do
# Ensure the gh-pages dir exists so we can generate into it.
task :check_gh_pages do
puts ""
puts "## Checking for gh-pages dir..."
puts "==============================="
puts ""
unless File.exist?("./_gh-pages")
puts "No gh-pages directory found. You need to:"
puts " 1. Set up a new github repository for the gh-pages site."
puts " 2. Clone that repository into the _gh-pages directory:"
puts ""
puts " git clone <repo name> _gh-pages"
puts ""
exit(1)
end
end
task :clean_gh_pages => :check_gh_pages do
# Copy to gh-pages dir.
puts ""
puts "## Removing everything from _gh-pages director (except .git and other hidden files)"
puts "==================================================================================="
puts ""
Dir.glob("_gh-pages/*") do |path|
sh "rm -rf #{path}"
end
end
task :generate_site do
puts ""
puts "## Generating site:"
puts "==================="
puts ""
puts "jekyll build"
puts ""
sh "jekyll build"
end
task :copy_site => :check_gh_pages do
puts ""
puts "## Copying _site to _gh-pages:"
puts "=============================="
puts ""
puts "cp -R _site/* _gh-pages"
puts ""
sh "cp -R _site/* _gh-pages"
end
task :commit_and_push => :check_gh_pages do
# Commit and push.
puts ""
puts "## Committing and pushing to GitHub Pages..."
puts "============================================"
puts ""
sha = `git log`.match(/[a-z0-9]{40}/)[0]
Dir.chdir('_gh-pages') do
sh "git add ."
sh "git add -u"
sh "git commit -m 'Updating to #{sha}.'"
sh "git push -f origin master:gh-pages"
end
puts 'Done.'
end
end