Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 93 lines (84 sloc) 2.727 kB
33dd181 @walkah new, jekyll-based blog
authored
1 module Jekyll
2 class TagIndex < Page
3 def initialize(site, base, dir, tag)
4 @site = site
5 @base = base
6 @dir = dir
7 @name = 'index.html'
8 self.process(@name)
9 self.read_yaml(File.join(base, '_layouts'), 'tag_index.html')
10 self.data['tag'] = tag
11 tag_title_prefix = site.config['tag_title_prefix'] || 'Posts Tagged &ldquo;'
12 tag_title_suffix = site.config['tag_title_suffix'] || '&rdquo;'
13 self.data['title'] = "#{tag_title_prefix}#{tag}#{tag_title_suffix}"
14 end
15 end
16
17 class TagFeed < Page
18 def initialize(site, base, tag_dir, tag)
19 @site = site
20 @base = base
21 @dir = tag_dir
22 @name = 'atom.xml'
23 self.process(@name)
24 # Read the YAML data from the layout page.
25 self.read_yaml(File.join(base, '_layouts'), 'tag_feed.xml')
c28cc89 @walkah htmlproof fixes (dead links, etc)
authored
26 self.data['tag'] = tag
33dd181 @walkah new, jekyll-based blog
authored
27 # Set the title for this page.
28 tag_title_prefix = site.config['tag_title_prefix'] || 'Posts Tagged &ldquo;'
29 tag_title_suffix = site.config['tag_title_suffix'] || '&rdquo;'
30 self.data['title'] = "#{tag_title_prefix}#{tag}#{tag_title_suffix}"
31 # Set the meta-description for this page.
32
33 # Set the correct feed URL.
34 self.data['feed_url'] = "#{tag_dir}/#{name}"
35 end
36 end
37
38 class TagGenerator < Generator
39 safe true
40 def generate(site)
41 if site.layouts.key? 'tag_index'
42 dir = site.config['tag_dir'] || 'tag'
43 site.tags.keys.each do |tag|
c28cc89 @walkah htmlproof fixes (dead links, etc)
authored
44 dest_dir = File.join(dir, tag.gsub(/ /, '-'))
45 write_tag_index(site, dest_dir, tag)
46 write_tag_feed(site, dest_dir, tag)
33dd181 @walkah new, jekyll-based blog
authored
47 end
48 end
49 end
50
51 def write_tag_index(site, dir, tag)
52 index = TagIndex.new(site, site.source, dir, tag)
53 index.render(site.layouts, site.site_payload)
54 index.write(site.dest)
55 site.pages << index
56 end
57
58 def write_tag_feed(site, dir, tag)
59 feed = TagFeed.new(site, site.source, dir, tag)
60 feed.render(site.layouts, site.site_payload)
61 feed.write(site.dest)
62 site.pages << feed
63 end
64
65 end
66 # Adds some extra filters used during the category creation process.
67 module Filters
68
69 # Outputs a list of categories as comma-separated <a> links. This is used
70 # to output the category list for each post on a category page.
71 #
72 # +categories+ is the list of categories to format.
73 #
74 # Returns string
75 #
76 def tag_links(tags)
77 tags = tags.sort!.map do |item|
c28cc89 @walkah htmlproof fixes (dead links, etc)
authored
78 item.gsub!(/ /, '-')
33dd181 @walkah new, jekyll-based blog
authored
79 "<a class='tag' href='/tag/#{item}/'>#{item}</a>"
80 end
81
82 case tags.length
83 when 0
84 ""
85 when 1
86 tags[0].to_s
87 else
88 "#{tags[0...-1].join(', ')}, #{tags[-1]}"
89 end
90 end
91 end
92 end
Something went wrong with that request. Please try again.