feat: complete MDX migration, stabilize environment & verify via E2E tests
Former-commit-id: ec3e64156a2e182535cbdcf0d975cd54603a517d
This commit is contained in:
21
lib/mdx.ts
Normal file
21
lib/mdx.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import matter from 'gray-matter';
|
||||
|
||||
const CONTENT_DIR = path.join(process.cwd(), 'content');
|
||||
|
||||
export async function getMdxContent(locale: string, slug: string) {
|
||||
const filePath = path.join(CONTENT_DIR, locale, `${slug}.mdx`);
|
||||
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const source = fs.readFileSync(filePath, 'utf8');
|
||||
const { content, data } = matter(source);
|
||||
|
||||
return {
|
||||
content,
|
||||
frontmatter: data,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user