forked from nodejs/nodejs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwithMarkdownContent.tsx
More file actions
35 lines (26 loc) · 1.08 KB
/
withMarkdownContent.tsx
File metadata and controls
35 lines (26 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { getLocale } from 'next-intl/server';
import type { FC } from 'react';
import { dynamicRouter } from '#site/next.dynamic';
const getMarkdownContent = async (locale: string, file: Array<string>) => {
const filePathname = dynamicRouter.getPathname(file);
// Retrieves the Markdown file source content based on the file path and locale
// Uses dynamic routing to locate and load the appropriate markdown file
// for the given locale and file path segments
const { source, filename } = await dynamicRouter.getMarkdownFile(
locale,
filePathname
);
// Parses the Markdown/MDX source content and transforms it into a React component
// Handles both standard Markdown and MDX files
const { content } = await dynamicRouter.getMDXContent(source, filename);
return content;
};
type WithMarkdownContentProps = {
file: Array<string>;
};
const WithMarkdownContent: FC<WithMarkdownContentProps> = async ({ file }) => {
const locale = await getLocale();
const content = await getMarkdownContent(locale, file);
return content || null;
};
export default WithMarkdownContent;