mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-15 10:24:50 +00:00
27 lines
643 B
TypeScript
27 lines
643 B
TypeScript
import unified from 'unified'
|
|
import remarkParse from 'remark-parse'
|
|
import remark2rehype from 'remark-rehype'
|
|
import rehypeStringify from 'rehype-stringify'
|
|
import rehypeRaw from 'rehype-raw'
|
|
import { readAsset } from '#assets'
|
|
|
|
export default async (req) => {
|
|
const markdown = unified()
|
|
.use(remarkParse)
|
|
.use(remark2rehype)
|
|
.use(rehypeRaw)
|
|
.use(rehypeStringify)
|
|
|
|
const id = req.url
|
|
|
|
const data = await readAsset(`content${id}`) || `content not found: ${id}`
|
|
|
|
if ((id as string).endsWith('.md')) {
|
|
return {
|
|
html: await markdown.process({ contents: data }).then(v => v.toString())
|
|
}
|
|
}
|
|
|
|
return data
|
|
}
|