forked from henryyan/henryyan.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
49 lines (42 loc) · 954 Bytes
/
Rakefile
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
require 'rubygems'
require 'rake'
require 'open-uri'
require 'multi_json'
require 'awesome_print'
require 'hashie'
require 'date'
class Post < Hashie::Mash
def date
d=Date._strptime(self['date'],"%m月 %d, %Y %H:%M")
Time.utc(d[:year], d[:mon], d[:mday], d[:hour], d[:min],
d[:sec], d[:sec_fraction], d[:zone])
end
def filename
"_posts/#{date.strftime('%Y-%m-%d')}-#{slug}.html"
end
def slug
self["permalink"].split('/').last
end
def body
self.content
end
end
task :pull do
posts = MultiJson.decode(open("http://blog.ossxp.com/feed/?feed=json").read).map{|p| Post.new(p) }
posts.each do |p|
if File.exists?(p.filename)
puts "- Blog post at #{p.filename} exists, ignoring"
else
puts "- Creating blog post at #{p.filename}"
File.open(p.filename,'w') do |f|
f.write <<-YAML
---
layout: post
title: "#{p.title}"
---
#{p.body}
YAML
end
end
end
end