public
Description:
Homepage: http://jackdanger.github.com/synecdoche
Clone URL: git://github.com/JackDanger/synecdoche.git
synecdoche / Rakefile
100644 69 lines (62 sloc) 1.815 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
ROOT = File.dirname(__FILE__)
 
desc "Publish the blog using the jekyll executable"
task :default do
  system "jekyll"
end
 
desc "Update the 'published' bit in posts if the post date is today or earlier"
task :update_published do
  require 'rubygems'
  require 'active_support'
  entries.each do |post|
    date = Date.parse(post.scan(/_posts\/(\d{4}-\d{2}-\d{2})/).flatten.first)
    updated = File.read(post).sub(/^published: (false|true)$/, "published: #{(date <= Date.today).to_s}")
    File.open(post, 'w') {|file| file.write(updated) }
  end
end
 
desc "work around for crappy-ass pages.github change"
task :doublespace do
  require 'rubygems'
  require 'active_support'
  entries.each do |post|
    sections = File.read(post).split('---')
    lines = sections.pop.split("\n")
    newlines = []
    lines.each do |line|
      newlines << line
      newlines << ''
    end
    sections << newlines.join("\n")
    File.open(post, 'w') {|f| f.write sections.join("---")}
  end
end
 
desc "Create a new post, pass P='The Title' to name the new entry, pass YET=n to postdate by n days"
task :new do
  require 'activesupport'
  date = Date.today
  date = date + ENV['YET'].to_i if ENV['YET']
  if ENV['P'] # custom title
    postname = ENV['P']
    slug = postname.gsub(/[^a-z0-9\-_\+]+/i, '-').downcase.chomp("-")
    post = "#{ROOT}/_posts/#{date}-#{slug}.textile"
  else # auto-incrementing title
    number = Dir.glob("#{ROOT}/_posts/#{date}*").size
    postname = "#{date}-#{number}"
    slug = postname
    post = "#{ROOT}/_posts/#{postname}.textile"
  end
  File.open(post, 'w') do |f|
    f.write <<-EOS
---
layout: post
title: #{postname}
permalink: #{slug}.html
published: false
author: Jack Danger Canty
---
 
EOS
  end
  system "mate #{post}"
end
 
def entries
  Dir.glob("./_posts/*")
end