Skip to content

Instantly share code, notes, and snippets.

@scotu
Forked from ivey/jekyll.thor
Created August 23, 2011 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scotu/1166867 to your computer and use it in GitHub Desktop.
Save scotu/1166867 to your computer and use it in GitHub Desktop.
require 'fileutils'
class Jekyll < Thor
include FileUtils
method_options :format => :optional
desc "draft NAME", "Create draft `NAME` in _drafts"
def draft(name)
format = options[:format] || "markdown"
slug = name.downcase.gsub(/ +/,'-').gsub(/[^-\w]/,'').sub(/-+$/,'')
filename = slug + ".#{format}"
mkdir_p "_drafts"
if File.exists?("_drafts/#{filename}")
puts "#{filename} already exists!"
return
end
File.open("_drafts/#{filename}","w+") do |f|
f.puts "---"
f.puts "layout: post"
f.puts "title: #{name}"
f.puts "---"
end
puts "Created _drafts/#{filename}"
end
desc "publish FILE", "Publish file"
def publish(file=nil)
unless file
puts "Choose file:"
@files = Dir["_drafts/*"]
@files.each_with_index { |f,i| puts "#{i+1}: #{f}" }
print "> "
num = STDIN.gets
file = @files[num.to_i - 1]
end
now = Date.today.strftime("%Y-%m-%d").gsub(/-0/,'-')
mv file, "_posts/#{now}-#{File.basename(file)}"
end
end
@noamross
Copy link

noamross commented Apr 20, 2012 via email

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