-
-
Save brantfaircloth/608362 to your computer and use it in GitHub Desktop.
start jekyll post from commandline and stage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
added date
to YAML front-matter.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
updated such that it was an amalgamation of previous gist and content from http://bjorkoy.com/2010/05/blogging-with-jekyll-git-and-slicehost/