2022-12-06 12:54:34 +00:00
|
|
|
import glob from 'fast-glob'
|
|
|
|
import * as path from 'path'
|
|
|
|
|
|
|
|
async function importArticle(articleFilename) {
|
2023-01-14 19:31:05 +00:00
|
|
|
let {meta, default: component} = await import(
|
|
|
|
`../pages/writing/${articleFilename}`
|
|
|
|
)
|
|
|
|
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'], {
|
|
|
|
cwd: path.join(process.cwd(), 'src/pages/writing'),
|
|
|
|
})
|
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 19:31:05 +00:00
|
|
|
return articles.sort((a, z) => new Date(z.date) - new Date(a.date))
|
2022-12-06 12:54:34 +00:00
|
|
|
}
|