Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a collection using another collection #466

Closed
Max13 opened this issue May 5, 2020 · 7 comments
Closed

Generate a collection using another collection #466

Max13 opened this issue May 5, 2020 · 7 comments

Comments

@Max13
Copy link

Max13 commented May 5, 2020

I'm playing with the blog template, and I would like to generate the categories collection using the posts collections.

Currently, the template contains 1 file in source/_categories for each category known, but as it's possible to loop in the posts collection and look for the categories, it seems not to be possible to use a collection to generate another one (due to the fact that, collections aren't built (yet) during beforeBuild, and it's too late arriving at afterCollections to append a new one in config).

Is there a way or workaround to use a built collection (posts) to populate another (categories) ?

@damiani
Copy link
Contributor

damiani commented May 7, 2020

There isn't a built-in way to do this (at the moment), for exactly the reasons you described: collections are only processed once, so your categories collection can't automatically access the contents your posts collection.

There are some ideas for dynamically generating collections discussed here that we're exploring, but haven't yet nailed down an elegant implementation.

In the meantime, though, as mentioned in an issue from the blog template repo, I think @camuthig has a solution that might do what you're hoping: he wrote an afterCollections listener that checks the posts collection and adds any missing categories to the category collection, treating the generated pages as a remote collection (via the items key). Pretty slick solution, check it out.

@damiani damiani closed this as completed May 7, 2020
@Max13
Copy link
Author

Max13 commented May 7, 2020

Thank you for your suggestions

@paulofreitas
Copy link
Contributor

There isn't a built-in way to do this (at the moment), for exactly the reasons you described: collections are only processed once, so your categories collection can't automatically access the contents your posts collection.

There are some ideas for dynamically generating collections discussed here that we're exploring, but haven't yet nailed down an elegant implementation.

In the meantime, though, as mentioned in an issue from the blog template repo, I think @camuthig has a solution that might do what you're hoping: he wrote an afterCollections listener that checks the posts collection and adds any missing categories to the category collection, treating the generated pages as a remote collection (via the items key). Pretty slick solution, check it out.

Unfortunately the aforementioned solution no longer works because buildCollections() method is protected and so is $jigsaw->remoteItemLoader property. Couldn't find a way to achieve the same thing. :/

@camuthig
Copy link
Contributor

camuthig commented Aug 1, 2022

@paulofreitas you are correct about the protected status of the $jigsaw->remoteItemLoader. I haven't looked at that particular package for a while, but it seems like the pattern was broken back in 2020.

I dug into it a bit, and it looks like we should be able to access the same loader directly via the container, which is still publicly available on the Jigsaw instance: $jigsaw->app->get(CollectionRemoteItemLoader::class);

I created a branch, and it seems to work on my machine. Would you be willing to try using this branch instead of dev-master and confirm if it resolves your issues? camuthig/jigsaw-blog-default-categories#1

@palexandrite
Copy link

@camuthig please, let me know how to make pagination by your extension?

@camuthig
Copy link
Contributor

camuthig commented Mar 4, 2023

@palexandrite I haven't worked with this project much in recent years. If you add pagination to the general category layout, does it not add it to the generated ones as well? I'm not immediately sure how to add pagination to the user-defined category layout, so hard for me to quickly say how to add it to the generated ones.

@palexandrite
Copy link

palexandrite commented Mar 6, 2023

@camuthig thank you pretty much for your answer.

About the pagination in Jigsaw, I should make the pagination by YAML syntax in a head of a file (such as an extended layout or a page of a main category according to the Jigsaw documentation. But the pagination shown only for simple pages not for pages of collections.

It would be nice to have a pagination in a page of a collection :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants