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

Hi there,

I think this is the plugin I need, but would you be able to explain it's behavior? Does it render posts that are marked published: false, or does it render posts that are in a separate _drafts directory? Is the post content rendered elsewhere, like on the home page, or only in the draft files? Thanks!

@scotu
Copy link
Author

scotu commented Apr 20, 2012

Hi,

I'm sorry, I'm not the author and I never really used this code (it was forked from https://gist.github.com/49630/8d35667f8969816c6f7fd1f691985a666e446f85)

As far as a non rubist (me) can tell, this script creates two thor "tasks":

  • draft which takes non optional filename as parameter (and another optional parameter for the file format) that creates a file in a _draft/ dir
  • publish that takes one draft in _draft/, renames it with the current date and moves it to _posts/

@scotu
Copy link
Author

scotu commented Apr 20, 2012

to be clearer: it should not "render" anything, just preparing a draft (that does not get rendered) and publishing it (so that normal jekyll behaviour will render it if "published: true")

@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