Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Jekyll for category archive.
---
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>
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 &ldquo;'
category_title_suffix = site.config['category_title_suffix'] || '&rdquo;'
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
# 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