export function getPages() {
    const paths = import.meta.glob("/src/data/pages/*.md", { eager: true });

    const pages = [];
    for (const path in paths) {
        const file = paths[path]
        const slug = path.split('/').at(-1)?.replace('.md', '')

        if (file && typeof file === 'object' && 'metadata' in file && slug) {
            const metadata = file.metadata

            // hopefully this will get my attention
            if (!metadata.title) throw `${slug} doesn't have a title`;
            if (!metadata.description) throw `${slug} doesn't have a description`;

            pages.push({ ...metadata, slug });
        }
    }

    const byTitle = pages.filter((page) => !page.published).sort((a, b) => a.title > b.title);
    const byDate = pages.filter((page) => page.published).sort((a, b) => {
        const aDate = Date.parse(a.published);
        const bDate = Date.parse(b.published);
        if (aDate == bDate) return a.title > b.title;
        aDate < bDate;
    });

    return byTitle.concat(byDate);
}