33 lines
1.2 KiB
TypeScript
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
|
|
};
|
|
}
|