-
-
Notifications
You must be signed in to change notification settings - Fork 493
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
Eleventy collection from external REST API loses default collection item data structure #1093
Comments
This is really interesting and it's one of my own struggles. Data from APIs is something of a second class citizen compared to the data which passes through the collection building API. It would be great to be able to pipe data from any JS data file through the collections API to get all of the good stuff mentioned and also to hook into the tag system which 11ty relies on quite heavily |
Yeah, exactly. I feel like that's what |
I can understand why some of it doesn't work because it is not necessarily building things to the filesystem (until you paginate) so how would it know what fileSlug to build etc... But for me hooking into the tags is very important because tags are the (only native) way of carrying out filtering and query building on collections. |
This is a very good point. I'm facing it as I try to migrate a blog from .md files to headless CMS. The way you implemented it is the natural way that came to my mind. I faced the eact same problem as I have to fix many points that could have been solved. Now I will certainly fix this manually... |
Maybe that helps: https://benmyers.dev/blog/eleventy-data-cascade/ |
Yes, whatever you return from Starting with Eleventy 3.0, you should be able to use Virtual Templates, by taking advantage of the fact that you’ll be able to define an async config file that waits for your API call. |
I'm trying to build an Eleventy collection from external data, while keeping the default collection item data structure.
I have a REST API that serves JSON content, which looks like this:
GET https://mysite.example/api/articles
:Here is my Eleventy configuration:
.eleventy.js
:This results in an
articles
collection being successfully created in Eleventy, which is great! However, each collection item does not have the expected collection item data structure. I would expect that the returned data for each item would be added to adata
key, and the other default keys would also exist:inputPath
,fileSlug
,outputPath
,url
,date
,data
,templateContent
.Instead, those default keys are not added, and each collection item's data lives at the top level, instead of nested inside a
data
key.data
key, and programmatically try to create the other default keys?The text was updated successfully, but these errors were encountered: