Skip to content
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
26 changes: 24 additions & 2 deletions src/pages/jobs.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, CollectionEntry<"jobs">[]> = {};

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) {
Expand All @@ -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;
});
Comment on lines +60 to +71
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a JS developer, but this looks complicated to me - I think we can assume that each sponsor has a tier assigned. Otherwise we wouldn't be able to create one, no?

In that case, I think something as simple as sponsors.filter((s) => s.data.jobs.length).sort((a, b) => tiers.indexOf(a.data.tier) - tiers.indexOf(b.data.tier)); might work (I didn't try to run it, I'm guessing here) and is more readable, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We care only about sponsors with tier which allows to job posts. Array of tiers is shorter then all tiers that we have.

---

<Layout
Expand All @@ -55,8 +78,7 @@ sponsors.forEach((sponsor) => {

<Headline id="jobs" as="h1" title="Job board" />
{
sponsors.map((sponsor) => {
if (!(sponsor.data.jobs && sponsor.data.jobs.length > 0)) return;
sponsorsWithJobs.map((sponsor) => {
return (
<TwoCols>
<div slot="content" class="hidden lg:block">
Expand Down