-
-
Notifications
You must be signed in to change notification settings - Fork 475
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
Computed date from 11tydata.js in a directory not used in sorting collection. #2514
Comments
I think what's happening is that Eleventy sorts collections based on "the input file's Created Date", per https://www.11ty.dev/docs/collections/#sorting (but you can override content dates and alter sort order by specifying the … but by setting the date via Here was my test template: ---
title: Booleans
---
<h1>{{ title }}</h1>
<p>date={{ date }}</p>
<p>{{ page.date }}</p> This gave me the following output: <h1>Booleans</h1>
<p>date=2022-07-15</p>
<p>Thu Jul 28 2022 16:15:39 GMT-0700 (Pacific Daylight Saving Time)</p> So note that the One possible workaround is to create a new collection with the same name as the specified collection, and custom sort based on the eleventyConfig.addCollection("slides", function (collectionApi) {
return [...collectionApi.getFilteredByTag("slides")]
.sort((a, b) => new Date(a.data.date) - new Date(b.data.date));
}); |
I guess that makes some sense. Though it certainly went against my mental model that all the different ways of specifying data were eventually merged into the same place. And it halfway works that way, I guess. Anyway, this was only an issue because I was generating the template files from another system and it was a bit of a pain to put the date into the front matter which was why I was doing this in the first place. But I've since sorted that out. So leave it to you all to decide whether the current behavior is desired or not. Cheers! |
@gigamonkey I guess another solution is to rename your input file to something like /src/slides/2022-08-17-numbers.njk which will set the expected page date and fix your sorting; although that also means your output file would be something like /dest/slides/2022-08-17-numbers/index.html so you'd still end up setting the module.exports = {
tags: [ "slides" ],
permalink: "{{ page.filePathStem | url }}/"
}; [11ty] Writing www/slides/Numbers/index.html from ./src/slides/2022-04-17-Numbers.njk
[11ty] Writing www/slides/Booleans/index.html from ./src/slides/2022-07-15-Booleans.njk
[11ty] Writing www/slides/index/index.html from ./src/slides/index.njk
[11ty] Wrote 3 files in 0.05 seconds (v1.0.1) Where my ./src/slides/2022-07-15-Booleans.njk file looks like this: ---
title: Booleans
---
<h1>{{ title }}</h1>
<p>{{ page.date }}</p> <h1>Booleans</h1>
<p>Thu Jul 14 2022 17:00:00 GMT-0700 (Pacific Daylight Saving Time)</p> |
Describe the bug
Computed
date
from 11tydata.js in a directory not used in sorting collection.To Reproduce
Make two files in the same directory and collection (
slides
in this case) with the titlesNumbers
andBooleans
and then make a 11tydata.js file like this:Then put code like this somewhere to iterate over the collection:
Expected behavior
I would expect the items in the list to be sorted by the dates set in
slides.11tydata.js
.Instead the items are sorted as if there is no data value even though it is rendered in the output.
If I set the dates in the templates for the pages themselves. If I have
date
specified in both places for each page the sorting seems to be by the one in the template and the final output seems to come from the 11tydata.js file.Environment:
The text was updated successfully, but these errors were encountered: