export default function (eleventyConfig) { /* Create a single alt string from a multi-string alt object */ eleventyConfig.addFilter("createAlt", (altObject) => { let alt; if (altObject.length > 1) alt = `a ${altObject.length} picture collage.`; for (let i = 0; i < altObject.length; i++) alt += ` Image ${i + 1} is ${altObject[i]}`; return alt; }); /* What it says on the tin */ eleventyConfig.addFilter("randomize", function(array) { // Create a copy of the array to avoid modifying the original let shuffledArray = array.slice(); // Fisher-Yates shuffle algorithm for (let i = shuffledArray.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]]; } return shuffledArray; }); };