forked from cloudify-cosmo/getcloudify.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtag_gen.rb
More file actions
108 lines (96 loc) · 3.15 KB
/
Copy pathtag_gen.rb
File metadata and controls
108 lines (96 loc) · 3.15 KB
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
# Code based on http://mikewest.org/2009/11/my-jekyll-fork
# forked from http://github.com/rfelix/my_jekyll_extensions
require 'aop'
module Jekyll
class TagIndex < Page
# Initialize a new TagIndex.
# +base+ is the String path to the <source>
# +dir+ is the String path between <source> and the file
#
# Returns <TagIndex>
def initialize(site, base, dir, tag)
@site = site
@base = base
@dir = dir
@name = 'index.html'
self.process(@name)
self.read_yaml(File.join(base, '_layouts'), 'tag_index.html')
self.data['tag'] = tag
# MODIFIED by http://github.com/danc/
# related tags list ( other tags of any post tagged by 'tag')
# this code will not be run unless _config.yml declares :
# related_tags: true
if @site.config['related_tags']
related = []
site.tags[tag].each do |post|
post.tags.each do |rel|
related.push(rel) unless rel == tag || related.include?(rel)
end
end
self.data['related'] = related unless related.empty?
end
# END MODIFIED
tag_title_prefix = site.config['tag_title_prefix'] || 'Tag: '
self.data['title'] = "#{tag_title_prefix}#{tag}"
end
end
class TagAtom < Page
# Initialize a new TagIndex.
# +base+ is the String path to the <source>
# +dir+ is the String path between <source> and the file
#
# Returns <TagIndex>
def initialize(site, base, dir, tag)
@site = site
@base = base
@dir = dir
@name = 'atom.xml'
self.process(@name)
self.read_yaml(File.join(base, '_layouts'), 'tag_atom.xml')
self.data['tag'] = tag
# MODIFIED by http://github.com/danc/
# related tags list ( other tags of any post tagged by 'tag')
# this code will not be run unless _config.yml declares :
# related_tags: true
if @site.config['related_tags']
related = []
site.tags[tag].each do |post|
post.tags.each do |rel|
related.push(rel) unless rel == tag || related.include?(rel)
end
end
self.data['related'] = related unless related.empty?
end
# END MODIFIED
tag_title_prefix = site.config['tag_title_prefix'] || 'Tag: '
self.data['title'] = "#{tag_title_prefix}#{tag}"
end
end
class Site
# Write each tag page
#
# Returns nothing
def write_tag_index(dir, tag)
index = TagIndex.new(self, self.source, dir, tag)
index.render(self.layouts, site_payload)
index.write(self.dest)
end
def write_tag_atom(dir, tag)
index = TagAtom.new(self, self.source, dir, tag)
index.render(self.layouts, site_payload)
index.write(self.dest)
end
def write_tag_indexes
if self.layouts.key? 'tag_index'
self.tags.keys.each do |tag|
dir = self.config['tag_dir'] || 'tags'
self.write_tag_index(File.join(dir, tag), tag)
self.write_tag_atom(File.join(dir, tag), tag)
end
end
end
end
AOP.after(Site, :write) do |site_instance, result, args|
site_instance.write_tag_indexes
end
end