-
-
Save jaymcgavren/5984630 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
desc 'Create new post.' | |
task :new do | |
usage = 'rake new title="My title"' | |
title = ENV["title"] | |
time = Time.new | |
slug = title ? title.gsub(' ', '-').downcase : time.strftime('%H%M%S') | |
TARGET_DIR = "_posts" | |
filename = "#{time.strftime('%Y-%m-%d')}-#{slug}.markdown" | |
path = File.join(TARGET_DIR, filename) | |
post = <<-HTML | |
--- | |
layout: post | |
title: #{title || "''"} | |
tags: [] | |
published: true | |
--- | |
HTML | |
File.open(path, File::WRONLY|File::CREAT|File::EXCL) do |file| # Open file only if it doesn't exist | |
file.puts post | |
end | |
puts "New post generated at: #{path}" | |
system "open #{path}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment