2022-12-06 12:54:34 +00:00
|
|
|
import glob from 'fast-glob'
|
|
|
|
import * as path from 'path'
|
|
|
|
|
2023-01-14 22:42:49 +00:00
|
|
|
async function importArticle(articleFilename: string) {
|
2023-01-14 19:31:05 +00:00
|
|
|
let {meta, default: component} = await import(
|
2023-01-19 21:53:37 +00:00
|
|
|
`/pages/writing/${articleFilename}`
|
2023-01-14 19:31:05 +00:00
|
|
|
)
|
|
|
|
return {
|
|
|
|
slug: articleFilename.replace(/(\/index)?\.mdx$/, ''),
|
|
|
|
...meta,
|
|
|
|
component,
|
|
|
|
}
|
2022-12-06 12:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function getAllArticles() {
|
2023-01-14 19:31:05 +00:00
|
|
|
let articleFilenames = await glob(['*.mdx', '*/index.mdx'], {
|
2023-01-19 21:53:37 +00:00
|
|
|
cwd: path.join(process.cwd(), './pages/writing'),
|
2023-01-14 19:31:05 +00:00
|
|
|
})
|
2022-12-06 12:54:34 +00:00
|
|
|
|
2023-01-14 19:31:05 +00:00
|
|
|
let articles = await Promise.all(articleFilenames.map(importArticle))
|
2022-12-06 12:54:34 +00:00
|
|
|
|
2023-01-14 22:42:49 +00:00
|
|
|
return articles.sort((a, z) => a.date < z.date ? 1 : -1)
|
2022-12-06 12:54:34 +00:00
|
|
|
}
|