Creating pages from data files (json, yaml, etc) - possible? #40
-
|
Greetings, Does Lume support creating pages from data files, a la https://www.11ty.dev/docs/pages-from-data/? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
|
Yes, you have to create a page in javascript or typescript exporting a generator. You have an example with pagination here: https://lumeland.github.io/creating-pages/pagination/ Basically, every value returned by a generator will be converted to a page. The 11ty example would be something like this: // possum-pages.tmpl.js
export default function *({possums}) {
for (const possum of possums) {
yield {
url: `possums/${possum.name}/`,
content: `${possum.name} is ${possum.age} years old`
}
}
} |
Beta Was this translation helpful? Give feedback.
-
|
Excellent! Now I see that in the docs 🤦 Thanks for clarifying! |
Beta Was this translation helpful? Give feedback.
-
|
@oscarotero Maybe convert this issue to a discussion in section "Q&A"? |
Beta Was this translation helpful? Give feedback.
-
|
@shadowtime2000 That's a good idea. Can we move/convert this issue to a discussion? Or we need to create a new discusion from scratch? |
Beta Was this translation helpful? Give feedback.
-
|
@oscarotero I think you will be able to convert this issue to a discussion, just click "Convert to discussion" where it says pin issue and transfer issue. |
Beta Was this translation helpful? Give feedback.
Yes, you have to create a page in javascript or typescript exporting a generator. You have an example with pagination here: https://lumeland.github.io/creating-pages/pagination/
Basically, every value returned by a generator will be converted to a page. The 11ty example would be something like this: