-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
Unable to override the content date in eleventyComputed property #2199
Comments
See also:
I don't like it [at all] but this hacky trick might work: ---js
{
pagination: {
data: "pages",
size: 1,
alias: "pg",
addAllPagesToCollection: true
},
permalink: "/page/{{ pg.date }}/{{ pg.title | slug }}/",
eleventyComputed: {
date(data) {
const _date = new Date(data.pg.date);
// HACK: Inject the computed date into the internal `page` object. Eeww.
data.page.date = _date;
return _date;
}
}
}
---
title={{ pg.title }}
pg.date={{ pg.date }}
eleventyComputed.date={{ date }}
page.date={{ page.date }}
page={{ page | inspect | safe }} Where my ./src/_data/pages.js looks like this: module.exports = [
{ title: "page 1", date: "01/02/2022" },
{ title: "page 2", date: "02/03/2022" },
{ title: "page 3", date: "03/04/2022" },
]; OUTPUT (./www/page/03/04/2022/page-3/index.html)title=page 3
pg.date=03/04/2022
eleventyComputed.date=Fri Mar 04 2022 00:00:00 GMT-0800 (Pacific Standard Time)
page.date=Fri Mar 04 2022 00:00:00 GMT-0800 (Pacific Standard Time)
page={
date: 2022-03-04T08:00:00.000Z,
inputPath: './src/index.njk',
fileSlug: '',
filePathStem: '/index',
outputFileExtension: 'html',
url: '/page/03/04/2022/page-3/',
outputPath: 'www/page/03/04/2022/page-3/index.html'
} |
Thanks @pdehaan! |
@pdehaan Sorry to add on a closed issue, but is there another way than your - yes hacky 😄 - but very practical solution? It seems the only way to pass "information" from a data set to collection built with pagination. |
@TigersWay I think my solution above is super hacky, but mostly only because In most cases I think using |
@pdehaan Thanks a lot for this hack, couldn't come up with any solution so I'm happy I stumbled upon this thread. I used it for both |
If I set the date like this in eleventy computed it doesn't override the file date:
It does work however when I move this out of a computed property:
The reason I need this is I eventually want to use the page data to set the date.
The text was updated successfully, but these errors were encountered: