Personalize the TOC based on document category and frontmatter #7850
-
|
I have a case where, for part of the documentation, I need to add some metadata to my page. Pages that requires it can just have, in the frontmatter, something like: displayMetadata: trueand then I can have an object like metadata: []Questions are:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
|
It looks similar to what @lanegoolsby is trying to do, see my answer here: #7644 (comment)
It depends The first question to ask yourself is: do you want to customize all Docusaurus TOCs (desktop? mobile?) at once, or just a specific case (desktop only? docs only?)
I'm not sure what you mean by that 🤷♂️ But:
Don't be too afraid by "internal", "unsafe" etc, those are too scary but what we mean in the end is just that we may have to do breaking changes on those apis someday, not that you shouldn't use those. If you only use these on your site's code, then you'd be able to adjust your code once we do breaking changes. It's very unlikely that we'll completely remove the TOC component or the 2 hooks above. |
Beta Was this translation helpful? Give feedback.
-
|
I can swizzle the TOC component fine, that works great. Where I'm stuck is in trying to convert the swizzled component into a custom plugin. |
Beta Was this translation helpful? Give feedback.
-
|
I have a working example using the My example is using a custom plugin, so a bunch of that is unnecessary if you can get away with swizzling. In my case I need the custom code to be reusable across multiple sites so needing to create the plugin complicates things a little. |
Beta Was this translation helpful? Give feedback.
It looks similar to what @lanegoolsby is trying to do, see my answer here: #7644 (comment)
It depends
The first question to ask yourself is: do you want to customize all Docusaurus TOCs (desktop? mobile?) at once, or just a specific case (desktop only? docs only?)
I'm not sure what you mean by that 🤷♂️ But:
useDoc().frontMatter.displayMetadatauseBlogPost().frontMatter.displayMetadataDon't be too afraid by "internal", "unsafe" etc, those are too scary but what we mean in the end is…