mirror of
https://github.com/r-freeman/portfolio.git
synced 2024-11-22 05:35:42 +00:00
Ryan Freeman
412927d663
All checks were successful
Build And Publish / BuildAndPublish (push) Successful in 2m45s
25 lines
732 B
TypeScript
25 lines
732 B
TypeScript
import glob from 'fast-glob'
|
|
import * as path from 'path'
|
|
|
|
async function importArticle(articleFilename: string) {
|
|
let {meta, default: component} = await import(
|
|
`/app/writing/${articleFilename}`
|
|
)
|
|
return {
|
|
slug: articleFilename.replace(/(\/page)?\.mdx$/, ''),
|
|
...meta,
|
|
component,
|
|
}
|
|
}
|
|
|
|
export async function getAllArticles(dateDesc = true) {
|
|
let articleFilenames = await glob(['*.mdx', '*/page.mdx'], {
|
|
cwd: path.join(process.cwd(), './app/writing'),
|
|
})
|
|
|
|
let articles = await Promise.all(articleFilenames.map(importArticle))
|
|
|
|
return dateDesc ? articles.sort((a, z) => a.date < z.date ? 1 : -1)
|
|
: articles.sort((a, z) => a.date > z.date ? 1 : -1)
|
|
}
|