jekyll-archives
jekyll-archives copied to clipboard
Is there multi-category support?
Can I list all posts on a page that belong to two categories, let's say, question
and ruby
? Right now I can list all posts either with category question
or ruby
but not both.
I think you can use Jekyll's where
filter for this..
Disclaimer: The following is untested.
{% assign question_category_posts = ... %}
{% assign ruby_question_category_posts = question_category_posts | where: "categories", "ruby" %}
Actually, I want to create a generic page to show posts belonging to two categories.
For example,
- If the URL is
www.blog.com/category/question/ruby
then show posts belonging to categoryquestion
andruby
. - If the URL is
www.blog.com/category/question/java
then show posts belonging to categoryquestion
andjava
. - If the URL is
www.blog.com/category/scala
then show posts belonging to categoryscala
only.
Is this possible with jekyll-archives
plugin or is there a better way?
If this feature isn't there in this plugin, it will be a good addition. We can add both and
and or
to combine different types.
Hi there,
Here is a workaround I figured out:
- Combine categories to a path like
question/java
def categories
categories = Hash.new
@posts.each do |post|
cats = post.data["categories"]
cate = ""
cats.each do |cat|
cate = cate +"/"+ cat
end
post_arr = categories.fetch(cate, [])
post_arr.append(post)
categories.store(cate, post_arr)
end
return categories
# @site.categories
end
- Modify
slugify_string_title
to do the slugifying by ourselves so that/
will not be replaced with-
.
def slugify_string_title
return unless title.is_a?(String)
Utils.slugify(title, :mode => @config["slug_mode"]) # handle this
end