-
Notifications
You must be signed in to change notification settings - Fork 106
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
MDX support including components and data #20
Comments
@khalilcodes it's a pretty big issue that we have to modify |
@khalilcodes also if this is complete can you move to in review in board? |
Based on further research into contentlayer it does look like you are supposed to be able to import components and assets. The key point is the that import directory is set to
|
@rufuspollock, @khalilcodes I've just tested another way to pass data to components, that doesn't require modifications to |
Overall, the next step here is some more research on MDX based approach |
when importing a component in md, it throws an error - For example the import statement as below:
gives the following error:
Further investigationIf the return statement of the component is a string, then it renders without any errors. for example if the following is the component: export function Button () {
return "This is a button component"
} and we import it in md like below: The result is as follows: |
@khalilcodes this looks like something on contentlayer - have you opened an issue yet in their issue tracker? That's the quickest way i think to get insight here. The issue would be something like: "How do import contents and data into my mdx documents" You should reference other relevant issues to indicate you have read them and made an effort to "read the docs" before asking. Then someone will likely answer even if to point to an existing issue. |
As per the suggestion i've opened an issue: contentlayerdev/contentlayer#273 yesterday. No response yet. |
@khalilcodes as next step can we commit two test pages (can be in site/content) showing it working and not working as per your notes with some sample component in the |
@rufuspollock would it be best if we commit these to a separate branch ? |
@khalilcodes don't think it is worth it and it would be good to have them deployed. Just put them in e.g. |
@rufuspollock added the test commits and commented on the issue with steps to reproduce. |
@rufuspollock based on the comment in the open issue, it has been suggested that the issue lies in our project setup and to rather use |
Can you wait for me to review before we do another trial. |
@rufuspollock, @khalilcodes I couldn't resist trying out (¯_(ツ)_/¯ 😄) so I'll share what I've found out
|
@rufuspollock, @khalilcodes I've added a bunch of comments to the issue description. Please take a look. |
I'm also almost done with creating a doc page so I'm not writing everything I've found while researching and testing MDX capabilities here. But basically importing custom components/data, defining custom components/data(variables) locally (directly within markdown), passing it then by props or evaluating JS expressions - all works. I'll submit a PR tomorrow. |
To make richer markdown pages we want MDX and be able to use components and data in the page e.g.
Acceptance
[x] A demo page working using a component and data that is passed in e.g.2022-08-11 (olayway:) we're no longer using demo pages<MyCoolComponent value={props.mydata} />
docs/howto-use-components-in-your-markdown
✅ 2022-07-07 see https://flowershow.app/docs/howto-use-components-in-your-markdown | 🚧 2022-08-11 (olayway:) 80% done, will include some context about MDX and how to import custom components/external data but also how to define them locally in a markdown file | 2022-08-15 done in PR Docs page on using custom components and data (and more broadly MDX) #89pages/[[slug]].js
| 🚧 2022-08-11 (olayway:) 80% done + no, you don't have to add the data inpages/[[slug]].js
- you can import it from external file or define it directly in markdown | 2022-08-15 done in PR Docs page on using custom components and data (and more broadly MDX) #89BONUS: find out if contentlayer supports direct imports in the MDX file e.g.
🚫 tried but not working and could not find, but next-mdx-remote does so I may be missing something ? ✅ 2022-08-22 (olayway:) yes, tested and works -> Contentlayer supports MDX and ESM
import
/export
statements are part of MDX standard syntax, currently you can see it working hereTasks
[ ] Demo page of component with props @ /demo2022-08-11 (olayway:) we're no longer using demo pages/docs/mdx
cuz I'm adding a bit context about MDX + it will include sections about: 1) how you can import custom components 2) how you can define components within markdown file (no importing) 3) how you can import data 4) how you can define data(variables) directly in your markdown | 2022-08-15 done in PR Docs page on using custom components and data (and more broadly MDX) #89Using components
https://github.com/contentlayerdev/website/blob/main/src/pages/docs/%5B%5B...slug%5D%5D.tsx
Options:
components/MDX.js
and use it in markdown eg.<MyComponent />
2022-08-11 (olayway:) no, you don't have to do that, but of course, you can - e.g. for the component you use across a lot of your md files so it makes sense to make them available globally.mdx
file too) 2022-08-11 (olayway:) works but you have to change React components' file extension from.js
to.jsx
(for reference, see comments from Contentlayer team on the issue we've submitted)Passing props
Can pass arguments to MDX renderer and access as
props
? ✅ YES❕2022-08-11 (olayway:) You can also define data directly in your markdown files or import them from JSON file into your markdown files and then pass it as props to your components
Add as global props ...
See https://spectrum.chat/mdx/general/resolved-how-to-use-props-or-variables-with-mdx-files~3cd95635-1d93-440e-9802-7571cacfd578 - gatsbyjs/gatsby#17551
The text was updated successfully, but these errors were encountered: