feat: update remix to latest version, use Promise.all to fetch all posts

This commit is contained in:
2024-12-24 16:53:34 +01:00
parent 1057d40d78
commit d7952ad640
5 changed files with 264 additions and 139 deletions

View File

@@ -42,35 +42,38 @@ export type Post = Omit<FrontMatter, "published"> & {
export const findPosts = async () => {
const files = await readdir("posts");
const posts: Post[] = [];
for (const file of files.filter((file) => file.endsWith(".mdx"))) {
const filePath = path.join(process.cwd(), `posts/${file}`);
const postContent = (await readFile(filePath)).toString();
const { frontmatter } = await bundleMDX<FrontMatter>({
source: postContent,
mdxOptions() {
return {
remarkPlugins: [
[
remarkCodeHike,
{
theme: "one-dark-pro",
lineNumbers: true,
showCopyButton: true,
autoImport: true,
},
],
],
};
},
});
const posts = await Promise.all(
files
.filter((file) => file.endsWith(".mdx"))
.map(async (file) => {
const filePath = path.join(process.cwd(), `posts/${file}`);
const postContent = (await readFile(filePath)).toString();
const { frontmatter } = await bundleMDX<FrontMatter>({
source: postContent,
mdxOptions() {
return {
remarkPlugins: [
[
remarkCodeHike,
{
theme: "one-dark-pro",
lineNumbers: true,
showCopyButton: true,
autoImport: true,
},
],
],
};
},
});
posts.push({
...frontmatter,
filename: file.replace(".mdx", ""),
published: frontmatter.date.toISOString(),
});
}
return {
...frontmatter,
filename: file.replace(".mdx", ""),
published: frontmatter.date.toISOString(),
};
}),
);
return posts.sort((a, b) =>
new Date(a.published) > new Date(b.published) ? -1 : 1,