-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathRakefile
More file actions
157 lines (132 loc) · 3.75 KB
/
Rakefile
File metadata and controls
157 lines (132 loc) · 3.75 KB
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
# Rake tasks for Jekyll
# Inspired by https://github.com/imathis/octopress/blob/master/Rakefile
require 'rake/clean'
require 'redcloth'
require 'stringex'
require 'jekyll'
require 'rake'
require 'rdoc'
require 'date'
require 'yaml'
require 'tmpdir'
I18n.config.available_locales = :en
POSTS_DIR = '_posts'
BOOKS_DIR = '_books'
FRAGMENTS_DIR = '_fragments'
BUILD_DIR = '_site'
DEPLOY_DIR = '_deploy'
DEPLOY_BRANCH = 'gh-pages'
CLEAN.include BUILD_DIR
CLOBBER.include DEPLOY_DIR
desc 'Build the site'
task :build do
sh 'jekyll', 'build'
end
desc 'Start web server to preview site'
task :preview do
sh 'jekyll', 'serve', '--watch', '--drafts',
'--port', ENV.fetch('PORT', '4000')
end
desc 'Create a new draft'
task :new_draft, :title do |t, args|
title = args[:title] || 'New Draft'
filename = File.join('_drafts', "#{title.to_url}.md")
puts "==> Creating new draft: #{filename}"
open(filename, 'w') do |f|
f << "---\n"
f << "layout: post\n"
f << "title: \"#{title.to_html(true)}\"\n"
f << "comments: false\n"
f << "categories:\n"
f << "---\n"
f << "\n"
f << "Add awesome content here.\n"
end
end
desc 'Create a new post'
task :new_post, :title do |t, args|
title = args[:title] || 'New Post'
timestamp = Time.now.strftime('%Y-%m-%d')
filename = File.join(POSTS_DIR, "#{timestamp}-#{title.to_url}.md")
puts "==> Creating new post: #{filename}"
open(filename, 'w') do |f|
f.write "---\n"
f.write "layout: post\n"
f.write "title: \"#{title.to_html(true)}\"\n"
f.write "categories:\n"
f.write "---\n"
f.write "\n"
f.write "Add awesome post content here.\n"
end
end
desc 'Create a new book review'
task :new_book, :title do |t, args|
title = args[:title] || 'New Book Review'
timestamp = Time.now.strftime('%Y-%m-%d')
filename = File.join(BOOKS_DIR, "#{timestamp}-#{title.to_url}.md")
puts "==> Creating new book review: #{filename}"
open(filename, 'w') do |f|
f.write "---\n"
f.write "layout: book\n"
f.write "title: \"#{title.to_html(true)}\"\n"
f.write "categories:\n"
f.write "---\n"
f.write "\n"
f.write "Add awesome post content here.\n"
end
end
desc 'Create a new fragment'
task :new_fragment, :title do |t, args|
title = args[:title] || 'New Fragment'
timestamp = Time.now.strftime('%Y-%m-%d')
filename = File.join(FRAGMENTS_DIR, "#{timestamp}-#{title.to_url}.md")
puts "==> Creating new fragment: #{filename}"
open(filename, 'w') do |f|
f.write "---\n"
f.write "layout: post\n"
f.write "title: \"#{title.to_html(true)}\"\n"
f.write "categories:\n"
f.write "---\n"
f.write "\n"
f.write "Add awesome post content here.\n"
end
end
desc 'Create a new page'
task :new_page, :title do |t, args|
title = args[:title] || 'New Page'
filename = File.join(title.to_url, 'index.md')
puts "==> Creating new page: #{filename}"
mkdir_p title.to_url
open(filename, 'w') do |f|
f.write "---\n"
f.write "layout: page\n"
f.write "title: \"#{title.to_html(true)}\"\n"
f.write "---\n"
f.write "\n"
f.write "Add awesome page content here.\n"
end
end
desc "Generate blog files"
task :generate do
Jekyll::Site.new(Jekyll.configuration({
"source" => ".",
"destination" => "_site"
})).process
end
desc "Generate and publish blog to gh-pages"
task :publish => [:generate] do
Dir.mktmpdir do |tmp|
system "mv _site/* #{tmp}"
system "git checkout -B #{DEPLOY_BRANCH}"
system "rm -rf *"
system "mv #{tmp}/* ."
message = "Site updated at #{Time.now.utc}"
system "git add ."
system "git commit -am #{message.shellescape}"
system "git push origin gh-pages --force"
system "git checkout master"
system "rm -rf _site/"
system "echo yolo"
end
end
task :default => :publish