-
Notifications
You must be signed in to change notification settings - Fork 40
/
rakefile.rb
95 lines (82 loc) · 2.53 KB
/
rakefile.rb
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#Derived from https://github.com/avdgaag/arjanvandergaag.nl/blob/28539bc736a05b28f2aa4ef81e4f61f3f91375a0/Rakefile
task :default => :dev
MY_URL = "http://www.code52.org"
MY_NAME = "code52 team"
desc 'Ping pingomatic'
task :ping do
begin
require 'xmlrpc/client'
puts '* Pinging ping-o-matic'
XMLRPC::Client.new('rpc.pingomatic.com', '/').call('weblogUpdates.extendedPing', MY_NAME , MY_URL, MY_URL + '/rss.xml')
rescue LoadError
puts '! Could not ping ping-o-matic, because XMLRPC::Client could not be found.'
end
end
desc 'Notify Google of the new sitemap'
task :sitemap do
begin
require 'net/http'
require 'uri'
puts '* Pinging Google about our sitemap'
Net::HTTP.get('www.google.com', '/webmasters/tools/ping?sitemap=' + URI.escape(MY_URL + '/sitemap.xml'))
rescue LoadError
puts '! Could not ping Google about our sitemap, because Net::HTTP or URI could not be found.'
end
end
desc 'Run Jekyll in development mode'
task :dev do
puts '* Running Jekyll with auto-generation and server'
puts `jekyll --auto --server`
end
desc 'Run Jekyll to generate the site'
task :build do
puts '* Generating static site with Jekyll'
puts `jekyll`
end
desc 'Push source code to Github'
task :push do
puts '* Pushing to Github'
puts `git push github master`
puts '* Pushing to heroku'
puts `git push heroku master`
end
desc 'Generate and publish the entire site, and send out pings'
task :publish => [:build, :push, :sitemap, :ping] do
end
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