import type { Component } from 'svelte'; export interface PostMetadata { title: string; date: string; description: string; tags?: string[]; } export interface Post extends PostMetadata { slug: string; } export interface PostModule { default: Component; metadata: PostMetadata; } // Use Vite's glob import to get all .svx files from posts directory const postFiles = import.meta.glob('/src/posts/*.svx', { eager: true }); /** * Get all posts, sorted by date (newest first) */ export function getPosts(): Post[] { const posts: Post[] = []; for (const path in postFiles) { const file = postFiles[path]; // Extract slug from path: /src/posts/hello-world.svx -> hello-world const slug = path.split('/').pop()?.replace('.svx', '') ?? ''; if (file.metadata) { posts.push({ ...file.metadata, slug }); } } // Sort by date, newest first return posts.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()); } /** * Get a single post by slug */ export function getPost(slug: string): PostModule | undefined { const path = `/src/posts/${slug}.svx`; return postFiles[path]; }