From 8e0a87a61426ccbf8b9c03c0ee82fe6bc2911cd7 Mon Sep 17 00:00:00 2001 From: Niko Date: Wed, 25 Jun 2025 18:53:12 +0200 Subject: [PATCH] Add jobs order by the tier --- src/pages/jobs.astro | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/pages/jobs.astro b/src/pages/jobs.astro index d90b87872..e18d598ee 100644 --- a/src/pages/jobs.astro +++ b/src/pages/jobs.astro @@ -20,6 +20,15 @@ const jobsMap = Object.fromEntries(jobs.map((job) => [job.id, job])); const jobFiles = import.meta.glob("../content/sponsors/*/!(index).md"); const sponsorsJobsMap: Record[]> = {}; +const tiers = [ + "Keystone", + "Diamond", + "Platinum", + "Platinum X", + "Gold", + "Silver", +] as const; + for (const path in jobFiles) { const match = path.match(/\.\.\/content\/sponsors\/([^/]+)\/([^/]+)\.md$/); if (match) { @@ -46,6 +55,20 @@ sponsors.forEach((sponsor) => { collection: "jobs", })); }); + +// Sort sponsors by tier order +const sponsorsWithJobs = sponsors + .filter((sponsor) => sponsor.data.jobs && sponsor.data.jobs.length > 0) + .sort((a, b) => { + const aTierIndex = tiers.indexOf(a.data.tier as typeof tiers[number]); + const bTierIndex = tiers.indexOf(b.data.tier as typeof tiers[number]); + + // If tier not found in array, put it at the end + const aIndex = aTierIndex === -1 ? tiers.length : aTierIndex; + const bIndex = bTierIndex === -1 ? tiers.length : bTierIndex; + + return aIndex - bIndex; + }); --- { { - sponsors.map((sponsor) => { - if (!(sponsor.data.jobs && sponsor.data.jobs.length > 0)) return; + sponsorsWithJobs.map((sponsor) => { return (