-
Notifications
You must be signed in to change notification settings - Fork 17
/
team.rb
116 lines (95 loc) · 2.89 KB
/
team.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
module Jekyll
class TeamIndex < Page
def initialize(site, base, dir)
@site = site
@base = base
@dir = dir
@name = "index.html"
self.read_yaml(File.join(base, '_layouts'), 'team.html')
self.data['team'] = self.get_team(site)
self.process(@name)
end
def get_team(site)
{}.tap do |team|
Dir['_team/*.yml'].each do |path|
name = File.basename(path, '.yml')
config = YAML.load(File.read(File.join(@base, path)))
type = config['type']
if config['active']
team[type] = {} if team[type].nil?
team[type][name] = config
end
end
end
end
end
class PersonIndex < Page
def initialize(site, base, dir, path)
@site = site
@base = base
@dir = dir
@name = "index.html"
self.data = YAML.load(File.read(File.join(@base, path)))
self.data['title'] = "#{self.data['name']} | #{self.data['role']}"
self.process(@name)
end
end
class GenerateTeam < Generator
safe true
priority :normal
def generate(site)
write_team(site)
end
# Loops through the list of team pages and processes each one.
def write_team(site)
if Dir.exists?('_team')
Dir.chdir('_team')
Dir["*.yml"].each do |path|
name = File.basename(path, '.yml')
self.write_person_index(site, "_team/#{path}", name)
end
Dir.chdir(site.source)
self.write_team_index(site)
end
end
def write_team_index(site)
team = TeamIndex.new(site, site.source, "/team")
team.render(site.layouts, site.site_payload)
team.write(site.dest)
site.pages << team
site.static_files << team
end
def write_person_index(site, path, name)
person = PersonIndex.new(site, site.source, "/team/#{name}", path)
if person.data['active']
person.render(site.layouts, site.site_payload)
person.write(site.dest)
site.pages << person
site.static_files << person
end
end
end
class AuthorsTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text
@tokens = tokens
end
def render(context)
site = context.environments.first["site"]
page = context.environments.first["page"]
if page
authors = page['author']
authors = [authors] if authors.is_a?(String)
"".tap do |output|
authors.each do |author|
data = YAML.load(File.read(File.join(site['source'], '_team', "#{author.downcase.gsub(' ', '-')}.yml")))
template = File.read(File.join(site['source'], '_includes', 'author.html'))
output << Liquid::Template.parse(template).render('author' => data)
end
end
end
end
end
end
Liquid::Template.register_tag('authors', Jekyll::AuthorsTag)