-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
41 lines (32 loc) · 1.04 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
require 'rake'
require 'time'
namespace :blog do
namespace :post do
# Usage: rake blog:post:new title="A Title" [date="2012-02-09"]
desc "Create a New Blog Post"
task :new do
title = ENV["title"] || "new-post"
slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
begin
date = (ENV['date'] ? Time.parse(ENV['date']) : Time.now).strftime('%Y-%m-%d')
rescue Exception => e
puts "Error - date format must be YYYY-MM-DD, please check you typed it correctly!"
exit -1
end
filename = File.join("./_posts/", "#{date}-#{slug}.md")
date = Time.now.strftime("%Y-%m-%d %T %Z")
open(filename, 'w') do |post|
post.puts '---'
post.puts 'layout: post'
post.puts "date: #{date}"
post.puts "title: \"#{title.gsub(/-/,' ')}\""
post.puts 'categories: blog'
post.puts 'author: '
post.puts 'author_url: '
post.puts '---'
post.puts ''
end
system "#{ENV['EDITOR'] || 'open'} #{filename}"
end
end
end