From 62563f39de624237e9c05d7b09c6f6ffbdd4c631 Mon Sep 17 00:00:00 2001 From: Allison Truhlar Date: Thu, 23 May 2024 11:51:35 -0400 Subject: [PATCH] style: randomize order of project cards on page refresh --- src/pages/projects/index.astro | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pages/projects/index.astro b/src/pages/projects/index.astro index 91da40b..5169d83 100644 --- a/src/pages/projects/index.astro +++ b/src/pages/projects/index.astro @@ -19,10 +19,18 @@ import ToggleFilterMenuBtn from "../../components/projects/ToggleFilterMenuBtn"; import { extractUniqueTagsObject } from "../../utils/tagManipulation.js"; -const baseUrl = import.meta.env.BASE_URL; +function shuffleArray(array) { + for (let i = array.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [array[i], array[j]] = [array[j], array[i]]; // Swap elements + } + return array; +} +const baseUrl = import.meta.env.BASE_URL; const pageTitle = "OSSI-supported projects"; -const allProjects = await getCollection("projects"); +let allProjects = await getCollection("projects"); +allProjects = shuffleArray(allProjects); // uniqueTags is an object where keys = unique tag categories, values = unique tags within a category, both across allProjects. All lowercase. // used to populate the filter menu