Last active
February 10, 2016 00:37
-
-
Save nukos/decd091dec8d9635eb10 to your computer and use it in GitHub Desktop.
Jekyll for category archive.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
layout: default | |
--- | |
<h2 class="post_title">{{page.title}}</h2> | |
<ul> | |
{% for post in site.posts %} | |
{% for category in post.category %} | |
{% if category == page.category %} | |
<li class="archive_list"> | |
<time 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> | |
<p class="summary">{{post.summary}} | |
<ul class="tag_list"> | |
{% for category in post.category %} | |
<li class="inline archive_list"><a class="category_list_link" href="/category/{{ category }}">{{ category }}</a></li> | |
{% endfor %} | |
</ul> | |
</li> | |
{% endif %} | |
{% endfor %} | |
{% endfor %} | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Jekyll | |
class CategoryIndex < Page | |
def initialize(site, base, dir, category) | |
@site = site | |
@base = base | |
@dir = dir | |
@name = 'index.html' | |
self.process(@name) | |
self.read_yaml(File.join(base, '_layouts'), 'category_archive.html') | |
self.data['category'] = category | |
category_title_prefix = site.config['category_title_prefix'] || 'Posts Category “' | |
category_title_suffix = site.config['category_title_suffix'] || '”' | |
self.data['title'] = "#{category_title_prefix}#{category}#{category_title_suffix}" | |
end | |
end | |
class CategoryGenerator < Generator | |
safe true | |
def generate(site) | |
if site.layouts.key? 'category_archive' | |
dir = site.config['cateogry_dir'] || 'category' | |
site.categories.keys.each do |category| | |
write_category_index(site, File.join(dir, category), category) | |
end | |
end | |
end | |
def write_category_index(site, dir, category) | |
index = CategoryIndex.new(site, site.source, dir, category) | |
index.render(site.layouts, site.site_payload) | |
index.write(site.dest) | |
site.pages << index | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# category archive | |
category_title_prefix: カテゴリー: | |
category_title_suffix: ' ' | |
category_dir: category |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment