-
Notifications
You must be signed in to change notification settings - Fork 0
/
linklists.rb
executable file
·62 lines (49 loc) · 1.39 KB
/
linklists.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
module Jekyll
class Linklists < Generator
attr_accessor :linklists
def initialize(config)
@linklists = []
Dir[File.join(Dir.pwd, '_linklists', '*.yml')].each do |linklist_file|
begin
data = YAML.load_file(linklist_file)
raise "Invalid linklist - #{linklist_file}" if !data.is_a?(Array)
linklist = Linklist.new(File.basename(linklist_file, ".yml"))
linklist.links = data.map{ |link_data| Link.new(link_data) }
self.linklists << linklist
rescue => err
$stderr.puts "WARNING: Could not read linklist."
$stderr.puts "\t" + err.to_s
end
end
config['linklists'] = self.linklists.inject({}) { |hash,linklist| hash[linklist.name] = linklist ; hash }
end
# doesn't actually generate anything
def generate(site)
end
end
class Linklist
attr_accessor :name, :links
def initialize(name)
@name = name
@links = []
end
def to_liquid
{ "links" => self.links }
end
def inspect
"#<Jekyll:Linklist @name=#{self.name.inspect}>"
end
end
class Link
attr_accessor :options
def initialize(options = {})
@options = options
end
def to_liquid
self.options
end
def inspect
"#<Jekyll:Link @options=#{self.options.inspect}>"
end
end
end