Category page - need a page with a link to all posts of a category

I’m implementing categories/tags with some success. I have followed the steps at: https://kylewbanks.com/blog/creating-category-pages-in-jekyll-without-plugins and it seems that the pages are now being rendered under /blog/my-category/2019/06/19/mypost.html - which is good.

However, I’d like to have a list of categories at /blog/category/index.html

I’ve created a default.html page in my _category page, but am still seeing the webserver (WEBrick/1.4.2 (Ruby/2.6.3/2019-04-16)) showing the directories for the years and then the months and then the date that the post was created. Is there something I’m missing?

do you have repo we can look at?

do you mean in your category directory? doesn’t make sense.

Sure - here’s my repo - https://github.com/kabads/kabads.github.io/tree/Addingcategories

I’d like to link from the home page to a page at /blog/category/sysadmin.html that lists all the pages that are in that category/collection. Thanks.

Maybe you can have a look here:

Replacing tag with category it may work.

What I mean is, I think I know how to iterate over the categories, I just don’t know how to get jekyll to create the categories page(s) (i.e. /blog/category/sport, /blog/categiory/politics etc.). Once I have that page, I think I can list out the posts in that category there.

For starters your config is incorrect. You defined a collection called categories but your collection folder is named _category. Jekyll doesn’t know what to do with that folder and it’s contents which is why you aren’t getting any /categories/xxx pages in your _site folder.

Either rename _category to _categories or change the config to

collections:
  category:
    output: true

Doing either will build the category pages. But it looks like you have some Liquid errors in your _layouts/home.html file you’ll need to sort out. As well as a post.categories loop in your post.html layout. You used {{ }} in places where you need to use {% %}.

@mmistakes - thanks - I used categories as a collection instead of category as all the front matter is as ‘categories’ - instead of going through each post and changing it (although I could do that through a regex and sed).

As for the site.categories loop in posts - I’ll fix that. I need to read more about liquid. Thanks for your help.

So, I’ve made some progress and have the categories/index.html and each page rendering for each category.

I’m trying to iterate over the posts with each category - with contains page.title - however, the page.title is upcase and so the comparison doesn’t match (returning no posts). So, I tried to pipe downcase:

    {% for post in site.posts %}
    {% if post.categories contains page.title | downcase %}
    <li>{{ post.title }}</li>
    {% endif %}
    {% endfor %}

But get an error:

Liquid Warning: Liquid syntax error (line 27): Expected end_of_string but found pipe in "post.categories contains page.title | downcase" in /_layouts/categories.html

How can I run downcase on page.title in this context?

OK, a little more experimenting, and I manage to answer my own question, but it would be handy if anyone could follow up if this is a super clumsy way of solving the problem. I created a variable and then referenced that - however, I would expect the pipe to work in curly braces.

    {% assign category = page.title|downcase %}

    {% for post in site.posts %}
    {% if post.categories contains {{category}}  %}
    <li>{{ post.title }}</li>
    {% endif %}
    {% endfor %}

Is this something that could be developed further so that pipe downcase works in this condition?