Skip to content

Commit

Permalink
fix(site): make tag collection deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
TrebledJ committed Jun 8, 2024
1 parent 83bb6dd commit ef9f23c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions eleventy/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ module.exports = function (eleventyConfig) {
return counter;
});

eleventyConfig.addCollection('tags', collectionApi => (
collectionApi.getAll().filter(p => p.page.filePathStem.match(/tags\/.+/))
));
eleventyConfig.addCollection('tags', collectionApi => {
const pages = collectionApi.getAll().filter(p => p.page.filePathStem.match(/tags\/.+/));
// Tags are not deterministically sorted, since they're marked as the same 'date'. So let's sort dem!
pages.sort((p, q) => (p.page.fileSlug < q.page.fileSlug ? -1 : p.page.fileSlug > q.page.fileSlug ? 1 : 0));
return pages;
});

eleventyConfig.addCollection('specialTags', collectionApi => (
collectionApi.getAll()
.filter(p => p.page.filePathStem.match(/tags\/.+/))
.filter(p => p.data.special)
.map(p => p.data.tag)
.sort()
));

eleventyConfig.addCollection('postsr', collectionApi => (
Expand Down

0 comments on commit ef9f23c

Please sign in to comment.