refactor: update project data type
- add order property to set explicit ordering on projects page - make project link optional as not all projects have an accessible link
This commit is contained in:
@@ -23,7 +23,8 @@ const projects = defineCollection({
|
|||||||
description: z.string(),
|
description: z.string(),
|
||||||
tags: z.array(z.string()),
|
tags: z.array(z.string()),
|
||||||
image: image(),
|
image: image(),
|
||||||
link: z.string().url(),
|
link: z.string().url().optional(),
|
||||||
|
order: z.number().optional(),
|
||||||
startDate: z.coerce.date().optional(),
|
startDate: z.coerce.date().optional(),
|
||||||
endDate: z.coerce.date().optional(),
|
endDate: z.coerce.date().optional(),
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -105,17 +105,12 @@ export async function getPostsByTag(
|
|||||||
|
|
||||||
export async function getAllProjects(): Promise<CollectionEntry<'projects'>[]> {
|
export async function getAllProjects(): Promise<CollectionEntry<'projects'>[]> {
|
||||||
const projects = await getCollection('projects')
|
const projects = await getCollection('projects')
|
||||||
return projects
|
return projects.sort((a, b) => (a.data.order ?? Infinity) - (b.data.order ?? Infinity))
|
||||||
.sort((a, b) => (b.data.startDate?.valueOf() ?? 0) - (a.data.startDate?.valueOf() ?? 0))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const FEATURED_PROJECT_IDS = ['homelab', 'chitai', 'cue', 'portfolio']
|
|
||||||
|
|
||||||
export async function getFeaturedProjects(): Promise<CollectionEntry<'projects'>[]> {
|
export async function getFeaturedProjects(): Promise<CollectionEntry<'projects'>[]> {
|
||||||
const projects = await getAllProjects()
|
const projects = await getAllProjects()
|
||||||
return FEATURED_PROJECT_IDS
|
return projects.slice(0, 4)
|
||||||
.map(id => projects.find(p => p.id === id))
|
|
||||||
.filter((p): p is CollectionEntry<'projects'> => p !== undefined)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getProjectsFeaturedTags(maxCount: number): Promise<string[]> {
|
export async function getProjectsFeaturedTags(maxCount: number): Promise<string[]> {
|
||||||
|
|||||||
Reference in New Issue
Block a user