-
Notifications
You must be signed in to change notification settings - Fork 3
/
Rakefile
61 lines (51 loc) · 1.31 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
require 'yaml'
def jekyll(*opts)
jekyll = Dir["_jekyll/bin/jekyll"].first || "jekyll"
sh "bundle", "exec", jekyll, *opts
end
desc "Clean the built site"
task :clean do
sh "rm -rf _site"
end
desc "Run Jekyll in server mode"
task :serve do
jekyll "serve"
end
desc "Run a build of jekyll"
task :build do
jekyll "build"
cp "_htaccess", "_site/.htaccess"
end
desc "Deploy to deploy_path specified in config.yml"
task :deploy => :build do
sh "rsync -rtz --delete _site/ " + YAML.load_file("_config.yml")['deploy_path']
end
desc "Make a new post"
task :new do
require 'highline/import'
slug_input = ask('Slug: ')
slug = slug_input.gsub(/\s+/, '-').downcase
today = Time.now.strftime('%Y-%m-%d')
post = "_posts/#{today}-#{slug}.md"
File.open(post, 'w') do |post|
post.puts <<-MD.gsub(/^\s+/, '')
---
layout: post
title: #{slug_input}
abstract: #{slug}
---
MD
end
exec "#{ENV['EDITOR']} #{post}"
end
desc "Redates the most recent post to today"
task :redate do
require 'fileutils'
last = Dir["_posts/*.md"].last
today = Time.now.strftime('%Y-%m-%d')
redated = last.gsub(%r{^_posts/\d+-\d+-\d+}, "_posts/#{today}")
FileUtils.mv(last, redated) unless last == redated
end
desc "Alias for redate and deploy"
task :publish => [:redate, :deploy]
task :default => :serve