feat: source blog entrys at compile time to improve loading time
All checks were successful
Gitea Actions Demo / Build (push) Successful in 1m16s
Gitea Actions Demo / Upload (push) Successful in 9s

This commit is contained in:
2025-09-30 17:11:44 +02:00
parent 3aca1afecb
commit 4702e5bf89
2 changed files with 40 additions and 23 deletions

View File

@@ -0,0 +1,32 @@
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
};
}