Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: randomize order of project cards on page refresh #248

Merged
merged 1 commit into from
May 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/pages/projects/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down