feat: add research submodule and page
This commit is contained in:
parent
3d450a389b
commit
4a39e535a3
13 changed files with 217 additions and 10 deletions
27
utils/getDoc.ts
Normal file
27
utils/getDoc.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import matter from 'gray-matter'
|
||||
import { remark } from 'remark'
|
||||
import html from 'remark-html'
|
||||
|
||||
const docsDirectory = path.join(process.cwd(), 'research/docs')
|
||||
|
||||
export async function getDoc(id: string) {
|
||||
const fullPath = path.join(docsDirectory, `${id}.md`)
|
||||
|
||||
// read file contents
|
||||
const fileContents = fs.readFileSync(fullPath, 'utf8')
|
||||
|
||||
// parse file contents
|
||||
const { content, data } = matter(fileContents)
|
||||
|
||||
// convert markdown to html
|
||||
const processedContent = await remark().use(html).process(content)
|
||||
|
||||
// return id, content, and data
|
||||
return {
|
||||
id,
|
||||
content: processedContent.toString(),
|
||||
...data,
|
||||
} as any
|
||||
}
|
||||
35
utils/getDocs.ts
Normal file
35
utils/getDocs.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
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[]
|
||||
}
|
||||
2
utils/index.ts
Normal file
2
utils/index.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
export { getDoc } from './getDoc'
|
||||
export { getDocs } from './getDocs'
|
||||
Loading…
Add table
Add a link
Reference in a new issue