From ef9f23c46da33920abe1a0e433c7808dd260eff1 Mon Sep 17 00:00:00 2001 From: TrebledJ <39648915+TrebledJ@users.noreply.github.com> Date: Sun, 9 Jun 2024 02:01:24 +0800 Subject: [PATCH] fix(site): make tag collection deterministic --- eleventy/collections.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/eleventy/collections.js b/eleventy/collections.js index 99aedf114..2836a10c7 100644 --- a/eleventy/collections.js +++ b/eleventy/collections.js @@ -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 => (