Skip to content

Instantly share code, notes, and snippets.

@lushone
Forked from stammy/Rakefile
Created March 6, 2014 11:29
Show Gist options
  • Select an option

  • Save lushone/9387702 to your computer and use it in GitHub Desktop.

Select an option

Save lushone/9387702 to your computer and use it in GitHub Desktop.

Revisions

  1. @stammy stammy created this gist Jan 24, 2011.
    43 changes: 43 additions & 0 deletions Rakefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    # 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