From 45026eee4c93bbbe6141dd23a664abe6e9ff3ca2 Mon Sep 17 00:00:00 2001 From: nolawz Date: Tue, 3 Mar 2026 04:04:23 +0530 Subject: Added events section and components required for that --- src/lib/data-utils.ts | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib/utils.ts | 10 ++++++++++ 2 files changed, 64 insertions(+) (limited to 'src/lib') diff --git a/src/lib/data-utils.ts b/src/lib/data-utils.ts index f6e566a..ab0176f 100644 --- a/src/lib/data-utils.ts +++ b/src/lib/data-utils.ts @@ -21,6 +21,25 @@ export async function getAllPostsAndSubposts(): Promise< .sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf()) } +export async function getAllEvents(): Promise[]> { + const events = await getCollection('events') + return events + .sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf()) +} + +export function groupEventsByYear( + events: CollectionEntry<'events'>[], +): Record[]> { + return events.reduce( + (acc: Record[]>, post) => { + const year = post.data.date.getFullYear().toString() + ;(acc[year] ??= []).push(post) + return acc + }, + {}, + ) +} + export async function getAllProjects(): Promise[]> { const projects = await getCollection('projects') return projects.sort((a, b) => { @@ -40,6 +59,14 @@ export async function getAllTags(): Promise> { }, new Map()) } +export async function getAllTypes(): Promise> { + const events = await getAllEvents() + return events.reduce((acc, event) => { + acc.set(event.data.type, (acc.get(event.data.type) || 0) + 1) + return acc + }, new Map()) +} + export async function getAdjacentPosts(currentId: string): Promise<{ newer: CollectionEntry<'blog'> | null older: CollectionEntry<'blog'> | null @@ -99,6 +126,19 @@ export async function getAdjacentPosts(currentId: string): Promise<{ } } +export async function getAdjacentEvents(currentId: string): Promise<{ + newer: CollectionEntry<'events'> | null + older: CollectionEntry<'events'> | null + parent: CollectionEntry<'events'> | null +}> { + const allEvents = await getAllEvents() + const currentIndex = allEvents.findIndex((event) => event.id === currentId) + const newer = currentIndex > 0 ? allEvents[currentIndex - 1] : null + const older = + currentIndex < allEvents.length - 1 ? allEvents[currentIndex + 1] : null + return { newer, older, parent: null } +} + export async function getPostsByAuthor( authorId: string, ): Promise[]> { @@ -113,6 +153,13 @@ export async function getPostsByTag( return posts.filter((post) => post.data.tags?.includes(tag)) } +export async function getEventsByType( + type: string, +): Promise[]> { + const events = await getAllEvents() + return events.filter((event) => event.data.type === type) +} + export async function getRecentPosts( count: number, ): Promise[]> { @@ -120,6 +167,13 @@ export async function getRecentPosts( return posts.slice(0, count) } +export async function getRecentEvents( + count: number, +): Promise[]> { + const events = await getAllEvents() + return events.slice(0, count) +} + export async function getSortedTags(): Promise< { tag: string; count: number }[] > { diff --git a/src/lib/utils.ts b/src/lib/utils.ts index d4d8119..e2e005b 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -35,3 +35,13 @@ export function getHeadingMargin(depth: number): string { } return margins[depth] || '' } +export function capitalizeFirstLetter(val: string): string { + return String(val).charAt(0).toUpperCase() + String(val).slice(1); +} + +export const iconMappings = { + "workshop": "lucide:hammer", + "competition": "lucide:trophy", + "game": "lucide:gamepad-2", + "quiz": "lucide:brain" +} -- cgit v1.2.3