-
Notifications
You must be signed in to change notification settings - Fork 7
/
Rakefile
37 lines (31 loc) · 850 Bytes
/
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
require "pathname"
desc "rake new_post [post_name]"
task :new_post do
name = ARGV.last
task name.to_sym do; end
create_post(dasherize_file_name(name), "_posts/")
end
def dasherize_file_name(str)
str.downcase.gsub("<", "<").gsub(/[^\w<>#?!$]+/, "-")
end
def create_post(post_name, directory)
filename = "#{Time.now.utc.strftime("%Y-%m-%d")}-#{post_name}.md"
path = Pathname(directory + filename)
if path.exist?
puts "'#{path}' already exists."
else
path.write content
`$EDITOR #{path}`
puts "Created: #{path}"
end
end
def content
content = <<-TEMPLATE.gsub(/^ */, "".freeze)
---
title: "Enter a concise title."
date: "#{Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S")}"
permanent_url: "https://github.com/jollygoodcode/jollygoodcode.github.io/issues/"
description: ""
---
TEMPLATE
end