jekyll-archives icon indicating copy to clipboard operation
jekyll-archives copied to clipboard

Is there multi-category support?

Open rampatra opened this issue 4 years ago • 4 comments

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.

rampatra avatar Aug 08 '20 11:08 rampatra

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" %}

ashmaroli avatar Aug 08 '20 13:08 ashmaroli

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 category question and ruby.
  • If the URL is www.blog.com/category/question/java then show posts belonging to category question and java.
  • If the URL is www.blog.com/category/scala then show posts belonging to category scala only.

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

rampatra avatar Aug 08 '20 13:08 rampatra

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.

rampatra avatar Aug 08 '20 13:08 rampatra

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

xulihang avatar Dec 01 '21 09:12 xulihang