forked from dnsimple/dnsimple-developer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
62 lines (51 loc) · 1.57 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
require 'rubygems'
require 'bundler/setup'
require 'fileutils'
desc "Compile the site"
task :compile do
FileUtils.rm_r('output') if File.exist?('output')
`nanoc compile`
end
desc "Publish to developer.dnsimple.com"
task :publish do
FileUtils.rm_r('output') if File.exist?('output')
`nanoc compile`
ENV['GIT_DIR'] = File.expand_path(`git rev-parse --git-dir`.chomp)
osha = `git rev-parse refs/remotes/origin/gh-pages`.chomp
Dir.chdir('output') do
ENV['GIT_INDEX_FILE'] = gif = '/tmp/dev.gh.i'
ENV['GIT_WORK_TREE'] = Dir.pwd
File.unlink(gif) if File.file?(gif)
`git add -A`
tsha = `git write-tree`.strip
puts "Created tree #{tsha}"
if osha.size == 40
csha = `echo '#{MessageGenerator.new.generate}' | git commit-tree #{tsha} -p #{osha}`.strip
else
csha = `echo '#{MessageGenerator.new.generate}' | git commit-tree #{tsha}`.strip
end
puts "Created commit #{csha}"
puts `git show #{csha} --stat`
puts "Updating gh-pages from #{osha}"
`git update-ref refs/heads/gh-pages #{csha}`
`git push origin gh-pages`
end
end
class MessageGenerator
FLICKR_URL = 'http://api.flickr.com/services/feeds/groups_pool.gne?id=32584222@N00&lang=en-us&format=json&nojsoncallback=1'
def initialize
require 'json'
require 'net/http'
require 'uri'
end
def generate
photo = items.sample
author = photo["author"].slice(/\((.+)\)/, 1)
"#{photo["title"]} by #{author}\n#{photo["link"]}"
end
def items
body = Net::HTTP.get(URI.parse(FLICKR_URL))
json = JSON.parse(body)
json["items"]
end
end