-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
61 lines (52 loc) · 1.64 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
require "rubygems"
require "tmpdir"
require "bundler/setup"
require "jekyll"
require "stringex"
# Change your GitHub reponame eg. "kippt/jekyll-incorporated"
GITHUB_REPONAME = "bwheeler96/bwheeler96.github.io"
namespace :site do
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|
cp_r "_site/.", tmp
Dir.chdir tmp
system "git init"
system "git add ."
message = "Site updated at #{Time.now.utc}"
system "git commit -m #{message.inspect}"
system "git remote add origin [email protected]:#{GITHUB_REPONAME}.git"
system "git push origin master --force"
end
end
end
# usage rake new_post[my-new-post] or rake new_post['my new post'] or rake new_post (defaults to "new-post")
task :new_post, :title do |t, args|
if args.title
title = args.title
else
title = get_stdin("Enter a title for your post: ")
end
filename = "_posts/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.markdown"
if File.exist?(filename)
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
end
puts "Creating new post: #{filename}"
open(filename, 'w') do |post|
post.puts "---"
post.puts "layout: post"
post.puts "title: \"#{title.gsub(/&/,'&')}\""
post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}"
post.puts "comments: true"
post.puts 'excerpt: ""'
post.puts "categories: "
post.puts "---"
end
end