-
Notifications
You must be signed in to change notification settings - Fork 41
/
Rakefile
39 lines (33 loc) · 1.08 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
require 'yaml'
require 'stringex'
desc "Create a new post"
task :new_post, :title do |t, args|
mkdir_p './content/posts'
args.with_defaults(:title => 'New Post')
title = args.title
filename = "./content/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 'kind: article'
post.puts 'published: false'
post.puts "---\n\n"
end
system("stg", "new", "-m", "news: #{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 = "./content/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", "news: #{title}")
end