-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
57 lines (48 loc) · 1.21 KB
/
Rakefile
File metadata and controls
57 lines (48 loc) · 1.21 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
require 'git'
require 'date'
require 'nanoc3/tasks'
require 'nanoc-git/tasks'
SITEDIR = "_site"
desc "Compile, commit and push"
task :default => [:compile, :commit, :push]
desc "Compile site"
task :compile do
sh "nanoc compile"
end
desc "Commit compiled site and record new version"
task :commit => [:commit_site]
desc "Commit compiled site to Git"
task :commit_site do
g = Git.open(SITEDIR)
g.add site_files.map {|f| f.gsub(/^#{SITEDIR}\//, '')}
g.commit "Regenerated"
end
desc "Push committed site to GitHub"
task :push do
g = Git.open(SITEDIR)
g.push
end
namespace "post" do
desc "Given a title as an argument, create a new post file"
task :new, [:title] do |t, args|
now = DateTime::now()
filename = "#{now.strftime '%Y-%m-%d'}-#{args.title.gsub(/[\s\W]/, '_').downcase}.markdown"
path = File.join("content", "blog", filename)
if File.exist? path; raise RuntimeError.new("Won't clobber #{path}"); end
File.open(path, 'w') do |file|
file.write <<-EOS
---
kind: post
title: #{args.title}
created_at: #{now.rfc3339} #_
tags: []
---
Content goes here
EOS
end
puts "Now open #{path} in an editor."
end
end
def site_files
FileList["#{SITEDIR}/**/*"].find_all {|f| File.file? f}
end