1

How can I create a page for each category automatically in Jekyll ?

example:

the url of the post : https://UsrNm.github.io/Category1/Category2/2018/02/16/Post1.html

I want when I go to link like: https://UsrNm.github.io/Category1/Category2/

Get All posts in category Category1 and Category2

or when I go to link like: https://UsrNm.github.io/Category2/

Get All posts in category Category2 only

zahaby
  • 33
  • 10

2 Answers2

0

You can't do this automatically.

Well, you have 2 options:

The Jekyll way and the hackish way.

In pure Jekyll way you will need to create pages manually for each category, even if you have posts with multiple categories. Note that Jekyll doesn't have dynamic routing for this.

In hackish way you could use JavaScript to read the parameters in url and show/hide needed content. Idea is to render all of the posts(hidden by default) and create identifiers on them, proper way to do this would be adding html attribute data-category=cat1 and say that you have url like this /category?categories=cat1,cat2. You could then get categories from url and add logic in JavaScript to show just the ones that are actually in that categories.

halfer
  • 19,824
  • 17
  • 99
  • 186
Mario Nikolaus
  • 2,346
  • 1
  • 21
  • 28
0

You can use the gem jekyll-archives to do this kind of work, which is a plugin of jekyll.

Or if you want to do this manually, you can read this guide

You can see the example of my site

Tips: Github Pages do not support this. Thus, if you want to deploy this on Github pages, you can convert site to static files and push only _site dir to the repo, which has been mentioned at here :)

Jevan Wu
  • 41
  • 4