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

Plugin throws TypeError if collection doesn't exist #25

Open
colophonemes opened this issue Sep 21, 2016 · 4 comments
Open

Plugin throws TypeError if collection doesn't exist #25

colophonemes opened this issue Sep 21, 2016 · 4 comments

Comments

@colophonemes
Copy link

colophonemes commented Sep 21, 2016

Hey

First, thanks for the great plugin!

Second, just wondering why the plugin is so strict about requiring the collection to be present in the build. If I have a null collection (i.e. nothing in my build matches the pattern set on metalsmith-collections) then the plugin throws a TypeError (L37).

I back most of my Metalsmith sites with Contentful, so I'm not in complete control of which items will be in the build. If an editor removes all items from a particular Content Type then it's possible that the collection will be empty.

Could default behaviour just be skipping over missing/empty collections?

Cheers
Sam

@blakeembrey
Copy link
Owner

Interesting. I guess that's possible. Do you use predefined collections? I would have guessed the collection would be [] instead of null if there's no items.

@colophonemes
Copy link
Author

My metalsmith-collection and metalsmith-pagination settings are generated automatically for each content type. The difficulty is checking whether the collection actually contains any items at build time (because the Contentful data is pulled in after the build starts, but the pagination settings are defined beforehand). I agree that it's strange that it doesn't just create an empty collection — I'll do a bit of digging and see if there's an issue with my implementation.

@colophonemes
Copy link
Author

So, metalsmith-collections doesn't add any keys to the metadata if the pattern glob doesn't match anything in the build. I could create a hacky fix by running a plugin in between metalsmith-collections and metalsmith-pagination that adds an empty array to all the expected metadata key if it doesn't exist, but it seems like it wouldn't be a big deal to just let unmatched collections fall through rather than throwing the error. Would you be open to me submitting a pull request to that effect?

@colophonemes colophonemes reopened this Sep 21, 2016
@blakeembrey
Copy link
Owner

Sure, sounds good to me.

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

No branches or pull requests

2 participants