export async function getPosts(tag: string | null = null) { const allPostFiles = import.meta.glob('$content/post/*.md'); const iterablePostFiles = Object.entries(allPostFiles); let posts = await Promise.all( iterablePostFiles.map(async ([pathMarkdown, resolver]) => { const { metadata } = await resolver(); const pathPost = "/post/" + pathMarkdown.slice(pathMarkdown.lastIndexOf("/") + 1, -".md".length); return { meta: { ...metadata, date: new Date(metadata.date), }, path: pathPost }; }) ); if (tag) posts = posts.filter(obj => obj.meta.tags.includes(tag)) posts.sort((post1, post2) => { const date1: Date = post1.meta.date; const date2: Date = post2.meta.date; return date2.getTime() - date1.getTime(); }); return posts; } export async function getTags() { const allPostFiles = import.meta.glob('$content/post/*.md'); const iterablePostFiles = Object.entries(allPostFiles); const allPosts: string[][] = await Promise.all( iterablePostFiles.map(async ([_, resolver]) => { const { metadata } = await resolver(); return metadata.tags; }) ); return new Set(allPosts.flat()); }