Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import fs from 'fs'
- import path from 'path'
- import { compileMDX } from 'next-mdx-remote/rsc'
- import CodeBlock from "../../app/elements/CodeBlock";
- import InfoPanel from "../../app/elements/InfoPanel";
- const rootDirectory = path.join(process.cwd(), 'src/app', 'mdx-pages')
- const components = {
- // Define components here
- CodeBlock,
- InfoPanel,
- };
- export const getPostBySlug = async slug => {
- var realSlug = slug.replace(/\.mdx$/, '')
- const filePath = path.join(rootDirectory, `${realSlug}.mdx`)
- const fileContent = fs.readFileSync(filePath, { encoding: 'utf8' })
- const { frontmatter, content } = await compileMDX({
- source: fileContent,
- options: { parseFrontmatter: true },
- components: {components}
- })
- return { meta: { ...frontmatter, slug: realSlug }, content }
- }
- export const getAllPostsMeta = async () => {
- const files = fs.readdirSync(rootDirectory)
- let posts = []
- for (const file of files) {
- const { meta } = await getPostBySlug(file)
- posts.push(meta)
- }
- return posts
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement