Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/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"
# Author:Khaja Minhajuddin (
# Some constants
TEMPLATE = "template.markdown"
TARGET_DIR = "_posts"
# Get the title which was passed as an argument
title = ARGV[0]
# Get the filename
filename = title.gsub(' ','-')
filename = "#{'%Y-%m-%d') }-#{filename}.markdown"
filepath = File.join(TARGET_DIR, filename)
# Create a copy of the template with the title replaced
new_post =
new_post.gsub!('TITLE', title);
# Write out the file to the target directory
new_post_file =, 'w')
new_post_file.puts new_post
puts "created => #{filepath}"

This comment has been minimized.

Copy link
Owner Author

commented Sep 30, 2010

a couple of things which can improved in this:

  • Add some error handling
  • Accept an optional second argument which would be the number of days after which this article would be published
    e.g. ./new.rb "futurustic article" 10
    That should create a file with the timestamp 10 days from now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.