35 lines
795 B
TypeScript
35 lines
795 B
TypeScript
import fs from 'fs'
|
|
import path from 'path'
|
|
import matter from 'gray-matter'
|
|
|
|
const docsDirectory = path.join(process.cwd(), 'research/docs')
|
|
|
|
export const getDocs = () => {
|
|
const fileNames = fs.readdirSync(docsDirectory)
|
|
return fileNames.map((fileName) => {
|
|
|
|
console.log("HERE", fileName)
|
|
|
|
if (!fileName || fileName.includes('README.md')) {
|
|
return {
|
|
id: 'readme',
|
|
data: {},
|
|
}
|
|
}
|
|
// set id and full path
|
|
const id = fileName.replace(/\.md$/, '')
|
|
const fullPath = path.join(docsDirectory, fileName)
|
|
|
|
// read file contents
|
|
const fileContents = fs.readFileSync(fullPath, 'utf8')
|
|
|
|
// parse file contents
|
|
const { data } = matter(fileContents)
|
|
|
|
// return id and data
|
|
return {
|
|
id,
|
|
...data,
|
|
}
|
|
}) as any[]
|
|
}
|