Im using Eleventy/11ty site generator and I have a myData object structured like this
[ {name: one, data: [1,2,3]},
{name: two, data: [1,2,3,4]} ]
And I want to generate a set of paged directories of each, for example
/one/1.html, /one/2.html etc
/two/1.html, /two/2.html etc
Im able to use
pagination:
data: myData
size: 1
alias: test
permalink: "{{ test.name | slug }}/index.html"
to generate a single html file (/one/index.html
) with all the data from the object named "one".
However I cant figure out how to additionally page that data to get the desired structure.
CodePudding user response:
You should be able to use computed data JS front matter to get this to work:
~~~js
{
pagination: {
data: "flattenedData",
size: 1,
alias: "test",
},
permalink: "{{ test.name | slugify }}/{{ test.data }}",
eleventyComputed: {
flattenedData: ({ myData }) =>
myData.flatMap(({ name, data }) =>
data.map(d => ({ name, data: d }))
)
}
}
~~~