-
-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Programmatically create pages from data files #136
Comments
We don’t support a programmatic API yet but this is the ground that the pagination module covers! https://github.com/11ty/eleventy/blob/master/docs/pagination.md |
Moving this to be a feature request. This will require upvotes to get traction. This repository is now using lodash style issue management for enhancements. This means enhancement issues will now be closed instead of leaving them open. The enhancement backlog can be found here: https://github.com/11ty/eleventy/issues?utf8=%E2%9C%93&q=label%3Aneeds-votes+sort%3Areactions-%2B1-desc+ |
I was all set to vote for this until I discovered how pagination can do this for me. SO slick.
❤️ |
i am using this approach to convert a big json file into a bunch of pages. there are a couple of pain points with this though
theres a few other things that make using the |
A big use case for me when it comes to programmatically generating pages is the following: I have a const lang = 'en'
class BlogTemplateEN {
data() {
return {
pagination: {
data: `posts-${lang}`,
size: 1
},
permalink: props => {
return `/${lang}/blog${
props.pagination.pageNumber === 0
? ""
: `/${props.pagination.pageNumber + 1}`
}/index.html`;
}
};
}
render(props) {
// final template...
}
} Problem is: I then have to copy and paste the same file, solely changing the I'm super open to ways of solving this specific problem, but overall I miss an imperative API for creating pages as it'd be much easier to leverage JS without having to get into #558 and #463 will greatly help with this, as they'll give more power to JS, but it still won't be quite there yet, IMO! And hey, I'm down to helping with this API, count on me 😄 |
@hcavalieri can't you do something like this:
BlogTemplateEn.11ty.js
That way you don't need to duplicate code. |
That makes perfect sense, @therealshark ! I was trying to implement something similar but failed miserably, not much into classes haha The thing is, though, this approach has limitations: you have to create on file for each language, for each template. Say I'm fetching an array of languages from an API and their respective content: how would I go about setting this up? One way is to manually create files, or to pre-fetch the languages and use Honestly, I'm a bit of a control freak and really want to get into the nitty gritty of how and when pages will be created, and that's why I'm putting Eleventy on hold for a while in favor of other options such as Metalsmith. Love the project, would love to use it, but it needs to work better on Windows (less bugs) and allow for controlling page creation. And be sure that I'll contribute if I find the time in the near future 😄 Thanks for the input, though, definitely helped o/ |
Related #620 |
But does it work for the large collection? I have 24k pages to generate. If I fetch whole data in a single call (in _data folder) then the response will be huge. it may fail. |
Maybe I am missing something in the docs but I have an array of data from contentful that needs to get turned into pages using the same template. I'd love to hear how you'd approach this currently, but I think it would be amazing to be able to do something like this:
The text was updated successfully, but these errors were encountered: