Files
Blog/src/routes/+page.server.ts
Amy Retzerau 4702e5bf89
All checks were successful
Gitea Actions Demo / Build (push) Successful in 1m16s
Gitea Actions Demo / Upload (push) Successful in 9s
feat: source blog entrys at compile time to improve loading time
2025-09-30 17:11:44 +02:00

33 lines
1.2 KiB
TypeScript

import type { SvelteComponent } from 'svelte';
import type { MDsveXComponent } from '$lib/types';
export interface BlogEntry {
name: string;
src: string;
img: string;
date: string;
desc: string;
}
export function load() {
const blog_entries: BlogEntry[] =
Object.entries(import.meta.glob('/src/routes/blogs/**/+page.svx', { eager: true }))
.map(([key, value]) => [
key.split('/src/routes').pop()?.split('/+page.svx').slice(0, -1).pop() as string,
value as MDsveXComponent
])
.map(([link, val]) =>
typeof val.metadata?.src !== 'undefined' ? [val.metadata?.src, val] : [link, val]
)
.map(([link, val]) => {
val.metadata.date = Date.parse(val.metadata.date);
return [link, val];
})
.sort(([link1, a], [link2, b]) => b.metadata?.date - a.metadata?.date)
.map(([link, val]) => { return { src: link, title: val.metadata.title, img: val.metadata.img, date: new Date(val.metadata.date).toDateString(), desc: val.metadata.desc } })
return {
blogs: blog_entries
};
}