forked from agileiowa/jekyll-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
executable file
·131 lines (105 loc) · 3.76 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
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
require "rubygems"
require "tmpdir"
require "bundler/setup"
require "jekyll"
# Change your GitHub reponame eg. "kippt/jekyll-incorporated"
GITHUB_REPONAME = "agileiowa/jekyll-web"
task :default => [:watch]
desc "Watch the site and regenerate when it changes"
task :watch do
puts "Starting to watch source with Jekyll..."
#system "sass --update _sass:css -f -l -r ./_sass/bourbon/lib/bourbon.rb"
jekyllPid = Process.spawn("jekyll serve --watch --future")
#sassPid = Process.spawn("sass --watch _sass:css -l -r ./_sass/bourbon/lib/bourbon.rb")
trap("INT") {
[jekyllPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
exit 0
}
[jekyllPid].each { |pid| Process.wait(pid) }
end # task :watch
namespace :generate do
desc "Generate new Lean Coffee event: lean_coffee['2017-01-01']"
task :lean_coffee, :date do | t, args |
datestamp = Time.now.strftime('%F')
# publish 20 days before the event
event_date = Date.parse(args[:date])
publish_date = event_date - 20
puts "Publish Date: #{publish_date}"
event_month_name = event_date.strftime("%B")
puts "Event Month: #{event_month_name}"
post_filename = "_drafts/#{publish_date}-lean-coffee-#{event_month_name}.md"
template = File.read('_templates/lean-coffee-template.md')
post = template.gsub(/\{\{month\}\}/, event_month_name)
.gsub(/\{\{date\}\}/, args[:date])
File.open(post_filename, "w") { | f | f.puts post }
puts "Created Draft at #{post_filename}"
end
desc "Generate new post"
task :post, :post_title, :date, :time do | t, args |
datestamp = Time.now.strftime('%F')
post_filename = build_target_filename(datestamp, args[:post_title])
post_template = File.read('_templates/post-template.md')
post = post_template.gsub(/\{\{date\}\}/, args[:date])
.gsub(/\{\{time\}\}/, args[:time])
.gsub(/\{\{title\}\}/, args[:post_title])
File.open(post_filename, "w") { | f | f.puts post }
open_for_editing(post_filename)
end
def build_target_filename(datestamp, title)
file_title = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
"_posts/#{datestamp}-#{file_title}.md"
end
def open_for_editing(post_filename)
system "open #{post_filename}" if (/darwin/ =~ RUBY_PLATFORM)
system "start #{post_filename}" if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM)
end
end
namespace :site do
desc "Generate blog files"
task :generate do
Jekyll::Site.new(Jekyll.configuration({
"source" => ".",
"destination" => "_site",
"exclude" => ["Rakefile"]
})).process
end
task :check do
if (has_unpushed_commits())
puts "\e[31mYou have un-pushed changes. NO PUBLISH FOR YOU!!\e[0m"
exit 0
end
if (not_master_branch())
puts "\e[31mYou need to be on the master branch. NO PUBLISH FOR YOU!!\e[0m"
exit 0
end
end
def has_unpushed_commits()
system "git fetch origin master -q"
status = `git status -sb`
(status =~ /\[ahead \d{1,}\]/)
end
def not_master_branch()
current_branch = `git rev-parse --abbrev-ref HEAD`
(current_branch == 'master')
end
desc "Generate and publish blog to gh-pages"
task :publish => [:check] do
system "git submodule update --init"
Dir.chdir("_site/") do
`git status`
`git checkout gh-pages`
end
FileUtils.rm_r Dir.glob('_site/*')
Rake::Task['site:generate'].invoke
Dir.chdir("_site/") do
`git status`
`git add .`
message = "Site updated at #{Time.now.utc}"
`git commit -m #{message.inspect}`
system "git push origin gh-pages"
end
`git add .`
`git commit -m "update _site for publish"`
`git push origin master`
end
end