]> git.r.bdr.sh - rbdr/r.bdr.sh/blob - _plugins/tag_generator.rb
1f616b6cd5fe081494c17e92bc6b76e3118f71b4
[rbdr/r.bdr.sh] / _plugins / tag_generator.rb
1 module Jekyll
2
3 class TagIndex < Page
4 def initialize(site, base, dir, tag)
5 @site = site
6 @base = base
7 @dir = dir
8 @name = 'index.html'
9
10 self.process(@name)
11 self.read_yaml(File.join(base, '_layouts'), 'tag_index.html')
12 self.data['tag'] = tag
13
14 tag_title_prefix = site.config['tag_title_prefix'] || 'Tag: '
15 self.data['title'] = "#{tag_title_prefix}#{tag}"
16 self.data['description'] = "Lista de articulos con la etiqueta #{tag} en Abuguet, el blog mas guapo de videojuegos."
17 end
18 end
19
20 class TagGenerator < Generator
21 safe true
22
23 def generate(site)
24 if site.layouts.key? 'tag_index'
25 dir = site.config['tag_dir'] || 'tags'
26 site.tags.keys.each do |tag|
27 write_tag_index(site, File.join(dir, tag), tag)
28 end
29 end
30 end
31
32 def write_tag_index(site, dir, tag)
33 index = TagIndex.new(site, site.source, dir, tag)
34 index.render(site.layouts, site.site_payload)
35 index.write(site.dest)
36 site.pages << index
37 end
38 end
39
40 end