2023-11-26 09:36:23 -08:00
|
|
|
import glob from 'fast-glob';
|
2023-11-15 19:42:05 -08:00
|
|
|
|
2023-11-26 09:36:23 -08:00
|
|
|
interface BlogPost {
|
|
|
|
title: string;
|
|
|
|
description: string;
|
|
|
|
author: string;
|
|
|
|
date: string;
|
2023-11-15 19:42:05 -08:00
|
|
|
}
|
|
|
|
|
2023-11-26 09:36:23 -08:00
|
|
|
export interface BlogPostWithSlug extends BlogPost {
|
|
|
|
slug: string;
|
2023-11-15 19:42:05 -08:00
|
|
|
}
|
|
|
|
|
2023-11-26 09:36:23 -08:00
|
|
|
async function importBlogPost(filename: string): Promise<BlogPostWithSlug> {
|
|
|
|
let { article } = (await import(`../app/blog/${filename}`)) as {
|
|
|
|
default: React.ComponentType;
|
|
|
|
article: BlogPost;
|
|
|
|
};
|
2023-11-15 19:42:05 -08:00
|
|
|
|
|
|
|
return {
|
2023-11-26 09:36:23 -08:00
|
|
|
slug: filename.replace(/(\/page)?\.mdx$/, ''),
|
2023-11-15 19:42:05 -08:00
|
|
|
...article,
|
2023-11-26 09:36:23 -08:00
|
|
|
};
|
2023-11-15 19:42:05 -08:00
|
|
|
}
|
|
|
|
|
2023-11-26 09:36:23 -08:00
|
|
|
export async function getAllBlogPosts() {
|
2023-11-15 19:42:05 -08:00
|
|
|
let articleFilenames = await glob('*/page.mdx', {
|
2023-11-26 09:36:23 -08:00
|
|
|
cwd: './src/app/blog',
|
|
|
|
});
|
2023-11-15 19:42:05 -08:00
|
|
|
|
2023-11-26 09:36:23 -08:00
|
|
|
const posts = await Promise.all(articleFilenames.map(importBlogPost));
|
|
|
|
return posts.sort((a, z) => +new Date(z.date) - +new Date(a.date));
|
2023-11-15 19:42:05 -08:00
|
|
|
}
|