-
Notifications
You must be signed in to change notification settings - Fork 19
/
planet
executable file
·150 lines (116 loc) · 4.48 KB
/
planet
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env ruby
require 'gli'
require 'planet'
include GLI
TEMPLATES = {
author: '
<div class="author">
<img src="{{ image_url }}" style="width: 96px; height: 96;">
<span style="position: absolute; padding: 32px 15px;">
<i>Original post by <a href="{{ twitter_url }}">{{ author }}</a> - check out <a href="{{ blog_url }}">{{ blog_name }}</a></i>
</span>
</div>
',
header: '---
title: "{{ post_title }}"
kind: article
created_at: {{ post_date }}
author: {{ author }}
layout: post
---
',
planet: '## Planet.rb default config file, modify it and spawn awesomeness!
planet:
posts_directory: source/_posts/
templates_directory: source/_layouts/
blogs:
# Bare minimum to get it working
- author: "Cubox"
feed: "http://blog.cuboxlabs.com/atom.xml"
image: "http://cuboxlabs.com/img/cubox-humans/could-be-you.png"
- author: "Pablo Astigarraga"
feed: "http://blog.poteland.com/atom.xml"
image: "http://poteland.com/images/avatars/red_mage.png"
# Other fields:
twitter: "poteland"
url: "http://blog.poteland.com" # => only required for people that don\'t have a \'url\' field on their RSS/Atom field'
}
program_desc 'Planet.rb is an awesome feed-aggregator gem that consumes RSS/Atom feeds and outputs them in a format suitable to use with Octopress or Jekyll'
desc 'Parses planet.yml file for blogs and generates their posts in Jekyll compliant format under the _posts directory'
command :generate do |c|
c.action do |global_options,options,args|
conf = YAML.load_file('planet.yml')
@planet = Planet.new(
config: conf.fetch('planet', {}),
blogs: conf.fetch('blogs', [])
)
@planet.aggregate
@planet.write_posts
end
end
desc 'Creates basic planet.yml config file'
command :init do |c|
c.action do |global_options,options,args|
abort 'There is already a planet.yml file present' if File.exist? 'planet.yml'
File.open('planet.yml', 'w') { |f| f.write(TEMPLATES[:planet]) }
puts '=> Created default planet.yml'
end
end
desc 'Creates basic templates on the templates_directory specified in planet.yml'
command :create_templates do |c|
c.action do |global_options,options,args|
conf = YAML.load_file('planet.yml')
templates_dir = conf.fetch('planet').fetch('templates_directory', 'source/_layouts/')
FileUtils.mkdir_p(templates_dir)
if !File.exists?(templates_dir + 'author.html')
File.open(templates_dir + 'author.html', 'w') { |f| f.write(TEMPLATES[:author]) }
puts "=> Created default #{ templates_dir }author.html"
else
puts "=> Template #{ templates_dir }author.html already exists, skipping"
end
if !File.exists?(templates_dir + 'header.md')
File.open(templates_dir + 'header.md', 'w') { |f| f.write(TEMPLATES[:header]) }
puts "=> Created default #{ templates_dir }header.md"
else
puts "=> Template #{ templates_dir }header.md already exists, skipping"
end
end
end
desc 'Delete existing templates and recreate them'
command :update_templates do |c|
c.action do |global_options,options,args|
conf = YAML.load_file('planet.yml')
templates_dir = conf.fetch('planet').fetch('templates_directory', 'source/_layouts/')
author = templates_dir + 'author.html'
header = templates_dir + 'header.md'
File.delete(author) if File.exists?(author)
File.delete(header) if File.exists?(header)
response = `#{ $0 } create_templates`
puts response
end
end
pre do |global,command,options,args|
if command.name == :generate
conf = YAML.load_file('planet.yml')
templates_dir = conf.fetch('planet').fetch('templates_directory', 'source/_layouts')
FileUtils.mkdir_p(templates_dir)
files = { author: templates_dir + 'author.html', header: templates_dir + 'header.md' }
files.each do |name, path|
if !File.exists?(path)
puts "=> You are missing some files in your templates directory, planet.rb will create them for you - make sure to review them on #{ templates_dir }!"
response = `#{$0} create_templates`
puts response
elsif TEMPLATES[name] != File.read(path)
puts "!! WARNING: your planet.rb template files are different from the default, if you haven't made specific changes to them yourself then planet.rb default templates might have changed.Run 'planet update_templates' to override your current files with the newest default file available."
end
end
end
true
end
post do |global,command,options,args|
true
end
on_error do |exception|
true
end
exit GLI.run(ARGV)