Created
October 3, 2021 16:43
-
-
Save albertBarsegyan/6c2c13d41d2b42b204fae71ed6abe036 to your computer and use it in GitHub Desktop.
get markdown from file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import matter from 'gray-matter'; | |
| import path from 'path'; | |
| import fs from 'fs'; | |
| export default function getDocBySlug(slug, locale = 'us') { | |
| const docsDirectory = path.join(process.cwd(), '/src/content'); | |
| const realSlug = slug.replace(/\.mdx$/, ''); | |
| const fullPath = path.join(docsDirectory, slug, `${realSlug}.${locale}.mdx`); | |
| const fileContents = fs.readFileSync(fullPath, 'utf8'); | |
| const { content, data } = matter(fileContents); | |
| return { slug: realSlug, meta: data, content }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment