Skip to content

Commit cb185cf

Browse files
committed
Add tag functionality by following these instructions http://charliepark.org/tags-in-jekyll/
1 parent 16a638e commit cb185cf

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

_layouts/tag_index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
layout: default
3+
---
4+
<h2 class="post_title">{{page.title}}</h2>
5+
<ul>
6+
{% for post in site.posts %}
7+
{% for tag in post.tags %}
8+
{% if tag == page.tag %}
9+
<li class="archive_list">
10+
<time style="color:#666;font-size:11px;" datetime='{.{post.date | date: "%Y-%m-%d"}}'>{{post.date | date: "%m/%d/%y"}}</time> <a class="archive_list_article_link" href='{.{post.url}}'>{{post.title}}</a>
11+
<p class="summary">{{post.summary}}</p>
12+
<ul class="tag_list">
13+
{% for tag in post.tags %}
14+
<li class="inline archive_list"><a class="tag_list_link" href="/tag/{{ tag }}">{{ tag }}</a></li>
15+
{% endfor %}
16+
</ul>
17+
</li>
18+
{% endif %}
19+
{% endfor %}
20+
{% endfor %}
21+
</ul>

_plugins/tag_gen.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
class TagGenerator < Generator
17+
safe true
18+
def generate(site)
19+
if site.layouts.key? 'tag_index'
20+
dir = site.config['tag_dir'] || 'tag'
21+
site.tags.keys.each do |tag|
22+
write_tag_index(site, File.join(dir, tag), tag)
23+
end
24+
end
25+
end
26+
def write_tag_index(site, dir, tag)
27+
index = TagIndex.new(site, site.source, dir, tag)
28+
index.render(site.layouts, site.site_payload)
29+
index.write(site.dest)
30+
site.pages << index
31+
end
32+
end
33+
end

0 commit comments

Comments
 (0)