forked from radar/ryanbigg.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.rb
executable file
·37 lines (29 loc) · 1.04 KB
/
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
29
30
31
32
33
34
35
36
37
#!/usr/bin/env ruby
# Script to create a 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"
#
# Original Author:Khaja Minhajuddin (http://minhajuddin.com)
# Modifications by Ryan Bigg
# Some constants
require 'rubygems'
require 'bundler/setup'
require 'active_support/core_ext/string'
TEMPLATE = "template.markdown"
TARGET_DIR = "_posts"
# Get the title which was passed as an argument
title = ARGV[0]
# Get the filename
filename = title.parameterize
filename = "#{Time.now.strftime('%Y-%m-%d')}-#{filename}.markdown"
filepath = File.join(TARGET_DIR, filename)
# Create a copy of the template with the title replaced
new_post = File.read("_layouts/" + TEMPLATE)
new_post.gsub!('TITLE', title);
new_post.gsub!('PSD-ID', "PSD-" + (Dir["_posts/*.markdown"].count + 12).to_s)
# 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}"