Open mdo opened 6 years ago
Hi Mark, The front matter you posted looks good to me at first glance. I'm sorry but I can't test it right now but you should be able to iterate multiple categories the way you're doing it. There is an implicit 'OR' between the values.
There is an example 2 project in the source that you could use as a test, this example paginates on multiple categories like you want. Check to see if that works. If the example works then maybe something is going wrong with your project, if the sample however also doesn't work maybe there is a larger issue with your setup or there might be a regression bug in the source. https://github.com/sverrirs/jekyll-paginate-v2/tree/master/examples/02-category
I don't see an example there that creates a post loop to pull in all posts from any of the multiple categories. Perhaps I should've expanded on the code snippet in my first comment, but let's instead look at the 02-category
example page, byname.md
:
If you change the category: cars
to category: porsche, mercedes
, the page will not exist when Jekyll recompiles the page.
Hmm, you're right. Sorry I misunderstood. This is indeed a confusing behaviour as collections work in an OR way but it seems that I implemented the others to have an AND. I will have to investigate this further. Give me a few days. :)
We have just encountered this bug too, is there any update on it?
Hi @mdo, @rrees,
Have you tried the latest gem (v1.9.2) for the "page will not exist" problem, and using "categories" instead of "category"? This line has "categories" hardcoded. I tried @mdo's example with
categories: porsche, mercedes
and it worked.
@ibrado I did try categories and it didn't work I'll update the Gem and see what happens
@ibrado so upgrading the gem got rid of the problem of the page not generating but using categories
instead of category
resulted in no filtering of the posts being paginated. I'm checking our frontmatter against that in the example now.
Okay, our frontmatter does match the example but filtering does not occur when categories are used in the pagination configuration
Ok, I took another look at the source code here and here. I think categories
was a red herring, sorry. Please try:
category: porsche,mercedes
; orcategory:
- porsche
- mercedes
If that works, I could make a PR to allow spaces after commas (or semi-colons, as it turns out).
Am trying this out now myself. I just noticed the intersect_arrays
call, d'oh. Digging deeper.
Made some progress but cannot figure out why JPv2 is getting incorrectly-split categories (split at a space) immediately at generator startup.
["cars", "cars,", "grand", "touring,", "Porsche,", "sports", "car"]
from
categories: cars, grand touring, Porsche, sports car
Otherwise, I have categories using "or" now (on my local machine). Oh well. I'll get back to this.
Ok, so the "categories string is split by space" is a Jekyll thing. Given this, the correct JPv2 syntax for posts would be
category: cars, grand touring, etc
(spaces after the comma don't matter)
or
categories:
- cars
- grand touring
- etc
I updated examples/02-category/cars/_posts
to reflect this, and added 3 more examples under examples/02-category/categories
. I also added support for categories:
in pagination pages.
I've pushed my changes to my fork's "or-filter" branch in preparation for a PR. Would appreciate some tests, thanks...
gem "jekyll-paginate-v2", :github => "ibrado/jekyll-paginate-v2", :branch => "or-filter"
Here's a screenshot of "Porsche, Mercedes, & Toyota" with 3 items per pagination page:
I've been thinking about this, and an "and" filter still makes sense in certain cases, e.g. in the documentation we have an example for category: software, ruby
. If I also have Java software, they would of course also show up if we just use a pure "or" filter, which is not what I would want.
Should we support both "and" and "or"? One way to do it would be to use the "and" filter for "category" -- which kinda makes sense since "ruby software" could be thought of as a "singular" category -- and use the "or" filter for "categories". OTOH, this might be introducing confusing behavior. But then again, having something like category: software && ruby
might be unnecessarily complex.
Or maybe specify something like (category_|tag_)filter: all/any
? Probably the cleanest solution, but it might be feature creep.
Whichever way, using an "or" filter exclusively might break existing sites that rely on JPv2's use of an "and" filter, so we have to keep that in mind...
Any preferences/thoughts on this matter, @sverrirs?
I've been thinking about this and one thing I've come up with is similar to what you suggested. Basically to leverage a global setting that controls whether multiple values in tags/categories/collections are interpreted in a AND or OR relationship. I haven't yet come up with a solution I'm 100% happy with though...
I'm actually cleaning up a branch in preparation for a PR for this based on my last idea (*filter: any/all
) :-D I'll push in a while; maybe you can build on it...
BTW, collections are always an "or", right? Since a doc can only belong to one..? I haven't added filters for collections.
This still doesn't seem to be working. I've cloned the examples and have tried all the combinations of adding categories to the frontmatter discussed above. The only results I get are no filtering (meaning all posts are shown), or no output at all.
Any idea when a fix might be added?
Has anyone found a work-around for paginating multiple categories?
It looks like the changes from #73 have since been reverted for version 3.0. Rolling down to version 2.0 (which required also downgrading to Jekyll 3) and following the pattern laid out in that PR worked for me:
categories:
values:
- porche
- mercedes
matching: any
Hopefully there is a plan to re-introduce it in the new version (like #208)?
I'm working on updating a project from the deprecated jekyll-paginate to this one and running into an issue where we want our homepage to feature posts from any of multiple categories. When I list out the five plus categories in our frontmatter, the index page is straight up removed.
I've pulled in the latest from
master
since the last release and that indeed keeps the page, but there are no posts. I'm guessing this is because the multiple categories is doing an "and" join on them?Example frontmatter: