Last active
November 20, 2022 04:38
-
-
Save rparree/c5db7abbab314ef39d3ca6208b8302bf to your computer and use it in GitHub Desktop.
This file contains 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
// Working Version :) | |
import React from 'react'; | |
import {NextPageContext} from "next"; | |
import {i18n} from '../../i18n' | |
import ReactMarkdown from "react-markdown"; | |
import matter from "gray-matter"; | |
import StandardPage from "../../components/layout/standard-page"; | |
import {MDXProvider} from "@mdx-js/react"; | |
interface Props { | |
markdown: string, | |
meta: Object | |
} | |
const I18NMDXComponent = ({markdown, meta}: Props) => { | |
return ( | |
<StandardPage {...meta}> | |
<div className="content"> | |
<ReactMarkdown> | |
{markdown} | |
</ReactMarkdown> | |
</div> | |
</StandardPage> | |
); | |
}; | |
export const getServerSideProps = async (ctx: NextPageContext): Promise<any> => { | |
const fs = require("fs") | |
const currentLanguage = ctx.req ? ctx.req.language : i18n.language | |
const key = ctx.query.key; | |
const contents = fs.readFileSync(`src/markdown/${currentLanguage}/${key}.md`).toString() | |
const matterResult = matter(contents) | |
return { | |
props: { | |
markdown: matterResult.content, | |
meta: matterResult.data, | |
} | |
} | |
} | |
export default I18NMDXComponent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment