forked from vlandham/vlandham.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.rb
executable file
·28 lines (22 loc) · 804 Bytes
/
new.rb
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
#!/usr/bin/env ruby
# Script to create a jekyll blog post using a template. It takes one input parameter
# which is the title of the blog post
# e.g. command:
# $ ./new.rb "helper script to create new posts using jekyll"
# Some constants
TEMPLATE = "template.textile"
TARGET_DIR = "_posts"
# Get the title which was passed as an argument
title = ARGV[0]
# Get the filename
filename = title.gsub(' ','-')
filename = "#{ Time.now.strftime('%Y-%m-%d') }-#{filename}.textile"
filepath = File.join(TARGET_DIR, filename)
# Create a copy of the template with the title replaced
new_post = File.read(TEMPLATE)
new_post.gsub!('TITLE', title);
# Write out the file to the target directory
new_post_file = File.open(filepath, 'w')
new_post_file.puts new_post
new_post_file.close
puts "created => #{filepath}"