Skip to content

Instantly share code, notes, and snippets.

@rparree
Last active November 20, 2022 04:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rparree/c5db7abbab314ef39d3ca6208b8302bf to your computer and use it in GitHub Desktop.
Save rparree/c5db7abbab314ef39d3ca6208b8302bf to your computer and use it in GitHub Desktop.
// 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