jekyll / jekyll-archives

:books: Archive pages for your Jekyll tags and categories.
https://jekyll.github.io/jekyll-archives/
MIT License
438 stars 99 forks source link

Is there multi-category support? #160

Open rampatra opened 4 years ago

rampatra commented 4 years ago

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.

ashmaroli commented 4 years ago

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" %}
rampatra commented 4 years ago

Actually, I want to create a generic page to show posts belonging to two categories.

For example,

Is this possible with jekyll-archives plugin or is there a better way?

rampatra commented 4 years ago

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.

xulihang commented 2 years ago

Hi there,

Here is a workaround I figured out:

  1. 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
  1. 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