From 0c8cd04233c88c444f86bc59c4422bb646a46a8d Mon Sep 17 00:00:00 2001 From: John Bampton Date: Mon, 26 Jan 2026 06:29:33 +1000 Subject: [PATCH] Randomize user list on build --- .eleventy.js | 18 +++++++++++++++--- src/index.njk | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.eleventy.js b/.eleventy.js index 690720c9..b9d0e32b 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -23,9 +23,21 @@ module.exports = function(eleventyConfig) { } }); - // 3. Collection setup - eleventyConfig.addCollection("people", function(collectionApi) { - return collectionApi.getFilteredByGlob("src/users/*.yaml"); + // 2. The Randomized Collection + eleventyConfig.addCollection("randomPeople", function(collectionApi) { + // Grab all yaml files from the users folder + const people = collectionApi.getFilteredByGlob("src/users/*.yaml"); + + // Create a copy of the array to avoid mutating the original global collection + let shuffled = [...people]; + + // Fisher-Yates Shuffle + for (let i = shuffled.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]]; + } + + return shuffled; }); return { diff --git a/src/index.njk b/src/index.njk index ccaad356..f75d5eaf 100644 --- a/src/index.njk +++ b/src/index.njk @@ -54,7 +54,7 @@ layout: false
- {% for person in collections.people %} + {% for person in collections.randomPeople %}