-
-
Save lushone/9387702 to your computer and use it in GitHub Desktop.
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
# ignore the "bit" stuff.. only relevant to my custom jekyll fork | |
desc 'create new post or bit. args: type (post, bit), title, future (# of days)' | |
# rake new type=(bit|post) future=0 title="New post title goes here" slug="slug-override-title" | |
task :new do | |
require 'rubygems' | |
require 'chronic' | |
type = ENV["type"] || "bit" | |
title = ENV["title"] || "New Title" | |
future = ENV["future"] || 0 | |
slug = ENV["slug"].gsub(' ','-').downcase || title.gsub(' ','-').downcase | |
if type == "bit" | |
TARGET_DIR = "_bits" | |
elsif future.to_i < 3 | |
TARGET_DIR = "_posts" | |
else | |
TARGET_DIR = "_drafts" | |
end | |
if future.to_i.zero? | |
filename = "#{Time.new.strftime('%Y-%m-%d')}-#{slug}.markdown" | |
else | |
stamp = Chronic.parse("in #{future} days").strftime('%Y-%m-%d') | |
filename = "#{stamp}-#{slug}.markdown" | |
end | |
path = File.join(TARGET_DIR, filename) | |
post = <<-HTML | |
--- | |
layout: TYPE | |
title: "TITLE" | |
date: DATE | |
--- | |
HTML | |
post.gsub!('TITLE', title).gsub!('DATE', Time.new.to_s).gsub!('TYPE', type) | |
File.open(path, 'w') do |file| | |
file.puts post | |
end | |
puts "new #{type} generated in #{path}" | |
system "open -a textmate #{path}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment