Skip to content

Instantly share code, notes, and snippets.

@brantfaircloth
Forked from al3x/newpost.rb
Created October 3, 2010 07:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brantfaircloth/608362 to your computer and use it in GitHub Desktop.
Save brantfaircloth/608362 to your computer and use it in GitHub Desktop.
start jekyll post from commandline and stage
#!/usr/bin/ruby
# Create new jekyll post and open in textmate
# $ ruby _new.rb This is the title
# The arguments form the title
unless ARGV[0]
raise "Please provide a post title."
end
# Create a URL slug from the title
def slugify(title)
str = title.dup
str.gsub!(/[^a-zA-Z0-9 ]/,"")
str.gsub!(/[ ]+/," ")
str.gsub!(/ /,"-")
str.downcase!
str
end
# Create parameters
root = "/Users/bcf/Sites/b.atcg.us/"
title = ARGV.join(' ')
slug = slugify(title)
prefix = Time.now.strftime("%Y-%m-%d")
datetime = Time.now.strftime("%Y-%m-%d %H:%M:%S")
file = "#{prefix}-#{slug}.markdown"
path = File.join(root, "_posts/#{file}")
text = <<-eos
---
title: #{title}
layout: post
date: #{datetime}
---
eos
# Create a new file and open it in textmate
File.open(path, 'w') { |f| f.write(text) }
#system("mate #{path}")
system("mate", "-w", path)
#system("git", "add", path)
@brantfaircloth
Copy link
Author

updated such that it was an amalgamation of previous gist and content from http://bjorkoy.com/2010/05/blogging-with-jekyll-git-and-slicehost/

@brantfaircloth
Copy link
Author

added date to YAML front-matter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment