-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to convert dynamic data to MDX #55
Comments
mdx-bundler can absolutely take a string from your CMS and bundle it! In your const {code} = await bundleMDX(portfolioItem.portfolios[0].content)
return {
props: {
portfolioItem: portfolioItem.portfolios[0],
code,
}, Then add
There are a whole host of options that can improve the way MDX is handled depending on your needs which you can find here: https://github.com/kentcdodds/mdx-bundler#options |
Thank you for your reply :). I got error when I click the post with markdown text:
my 23 line is: my [slug].js file: |
Sounds like an error in the MDX, what is line 23 excluding any frontmatter, of the MDX you are getting from your cms? |
You mean what I got in content section in my graphCMS?
from my VSCode terminal:
|
MDX doesn't support indented code like that, wrapping it in |
What does the HTML look like? Has it put in |
Looks like mdx-bundler is doing its job :) Is tailwind-typography installed and configured? |
Thank you, everything works right now 👍 appreciate your help 😄 function metamorphose(protagonist,author){
if( protagonist.name.first === 'Gregor' && author.name.last === 'Kafka' ){
protagonist.species = 'insect';
}
} |
Syntax highlight is possible with a remark plugin, I use remarkHighlight to do it on my site |
Got an error:
export const getStaticProps = async ({ params }) => {
const portfolioItem = await getPortfolioItem(params.slug);
const { code } = await bundleMDX(portfolioItem.portfolios[0].content, {
xdmOptions(options) {
options.remarkPlugins = [
...(options.remarkPlugins ?? []),
remarkHighlight,
];
return options;
},
});
return code;
}; |
The return from for example: export const getStaticProps = async ({ params }) => {
const portfolioItem = await getPortfolioItem(params.slug);
const { code } = await bundleMDX(portfolioItem.portfolios[0].content, {
xdmOptions(options) {
options.remarkPlugins = [
...(options.remarkPlugins ?? []),
remarkHighlight,
];
return options;
},
});
return {props: {code}};
};
`` |
im my GraphCMS: content section i got:
And it still doesn't highlight the code as it is javascript syntax. export const getStaticProps = async ({ params }) => {
const portfolioItem = await getPortfolioItem(params.slug);
const { code } = await bundleMDX(portfolioItem.portfolios[0].content, {
xdmOptions(options) {
options.remarkPlugins = [
...(options.remarkPlugins ?? []),
remarkHighlight,
];
return options;
},
});
return { props: { code, portfolioItem: portfolioItem.portfolios[0] } };
}; I've imported: export default function Home({ portfolioItem, content, code }) {
const Component = React.useMemo(() => getMDXComponent(code), [code]);
return (
<div className="prose prose-xl max-w-none mt-4 text-justify dark:text-gray-100 mb-10 cms-content">
<Component />
</div>
)
} |
Hello, I got data on GraphCMS in markdown text and I'd like to convert it to MDX. Could you tell me how to do it? I've installed mdx-bundler.
content: portfolioItem.portfolios[0].content, // <--- it containts the markdown text from GraphCMS.
I tried with mdx-remote but there were errors with severity vulnerabilities
I got
The text was updated successfully, but these errors were encountered: