Repository navigation
feat(mdx-loader): the table-of-contents should display props passed to headings of imported MDX partials - #9773
anatolykopyl wants to merge 3 commits into
Conversation
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
|
I've come up with a crude way of preserving the data passed to props of Markdown partials. For now, this method only works if the prop is a literal, since the prop values are collected at build time. While not perfect, having only literals is almost always all that is needed when working with partials. Nonetheless, I think some work can be moved to runtime, to allow the use of any arbitrary expressions. |
⚡️ Lighthouse report for the deploy preview of this PR
|
slorber
left a comment
There was a problem hiding this comment.
😅 to be honest I'm not super fan of this
This only works in some cases and does not feel super robust either, and we'll have to handle the users complaining about things it does not support.
I'd prefer to explore another solution: what if we didn't stringify the headings in the first place?
What if we converted headings to JSX instead?
The TOC structure could look like:
export const toc = [
{
"value": <>Doc Heading</>,
"id": "doc-heading",
"level": 2
},
...__tocPartial(props),
]
Pre-flight checklist
Motivation
This PR allows the usage of props in partial MDX files.
Test Plan
This PR will be tested via dogfooding.
Test links
Deploy preview: https://deploy-preview-9773--docusaurus-2.netlify.app/
Relevant dogfooding page: https://deploy-preview-9773--docusaurus-2.netlify.app/tests/docs/tests/toc-partials/props
Related issues/PRs
fix #9772