Create MDX Blog in your app using Contentlayer and Next.js - 2nd Part
In this Blog we will learn advance mdx.
Faisal Husain
In the last blog we created simple mdx website using contenlayer and nextjs.
now in this blog we learn some advance technique's like
- how to create custom components
- how to add color to code blocks
- etc etc
suppose we have to create a component may which just highlight some text like a callout components how we will do that in mdx lets see.
first we create a custom component name callout.tsx
here something I am intentionally missing let you figure out that 😎
now import that callout inside mdx-component.tsx
now that callout look somthing like this
Hi from callout
this do not need to be this much ugly but you got the point.😒
like this you can create as many components as you need to create. from here your creativity take driver seat.
adding custom component part done
also you can refer shadcn and see how they write custom components refer here
now lets see how can we add highlighted codeblocks 👨💻
for adding themed codeblocks we need to install several dependancies
you can choose theme of code block from here
now comes the case to add line number and line highlight to code block
for this part i used this in this they have a file which make this lineNumber and linehighlight possible.
file contains styles for that file
paste this file in global.css
now if you type isCallLikeExpression
this will work like this
Thats it ,Thank you for reading
Here is link to repo which has all code.