Sometimes getting started can be the hard part. This applies to writing posts here in Jekyll (the framework I use to maintain this site). To make it even easier, I wrote a script that creates basic posts for you.

Use it like this:

{% highlight bash %} $ newpost --title "Post title goes here" {% endhighlight %}

Code below:

{% highlight ruby %}

!/usr/bin/env ruby

require 'optparse'

options = { :subdir => "_posts" }

parsed = do |opts| opts.banner = 'Usage: newpost --title "post title" [options]'

opts.on("-t", "--title TITLE") do |t| options[:title] = t options[:slug] = t.strip.downcase.gsub(/ /, '-') end

opts.on("-d", "--draft", "Create new post in drafts") do options[:subdir] = "drafts" end end.parse!

if options[:title].nil? or options[:title].strip == "" puts "Need post title. Specify using --title" exit 2 end

now = dateprefix = now.strftime("%Y-%m-%d") jekylldir = File.dirname(File.expandpath('.', _dir_)) postsdir = File.join(jekylldir, options[:subdir]) post = File.join(postsdir, "#{date_prefix}-#{options[:slug]}.md")

if File.exist?(post) puts "File already exists." exit 1 end

header = <<-END

date: #{now.strftime("%Y-%m-%d %H:%M:%S%z")} layout: post slug: "#{options[:slug]}" title: #{options[:title]} description:


h1. {{ page.title }} END, 'w') do |f| f << header end

editor = ENV['EDITOR'] unless editor puts "Created new post: \n#{post}" else system(editor, post) end {% endhighlight %}

Link to full gist