-
Notifications
You must be signed in to change notification settings - Fork 12
/
Rakefile
45 lines (38 loc) · 1.12 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
begin
require 'nanoc'
rescue LoadError
require 'rubygems'
require 'nanoc'
end
require 'yaml'
require 'stringex'
desc "Create a new post"
task :new_post, :title do |t, args|
args.with_defaults(:title => 'New Post')
title = args.title
filename = "_posts/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.md"
abort("#{filename} already exists") if File.exist?(filename)
puts "Creating new post: #{filename}"
open(filename, 'w') do |post|
post.puts '---'
post.puts "title: \"#{title}\""
post.puts "created_at: #{Time.now}"
post.puts "author: #{ENV['USER']}"
post.puts "layout: post"
post.puts "---\n\n"
end
system("stg", "new", "-m", "post: #{title}")
system("git", "add", filename)
system("stg", "refresh")
system("sensible-editor", filename)
metadata = YAML.load_file(filename)
p metadata
title = metadata['title']
date = metadata['created_at']
new_filename = "_posts/#{date.strftime('%Y-%m-%d')}-#{title.to_url}.md"
if new_filename != filename
system("git", "mv", filename, new_filename)
end
system("stg", "refresh")
system("stg", "edit", "-m", "post: #{title}")
end