Closed windmaomao closed 4 years ago
I'm closing this Issue since I didn't hear back from you. Feel free to reopen.
The answer here is that it does not work with latest versions of gatsby-theme-blog
because that plugin renders MDX using gatsby-plugin-mdx
, which is AFAIU a successor to gatsby-remark
and not compatible with it.
Fortunately, gatsby-plugin-mdx
automatically populates a tableOfContents
structure in page data.
Unfortunately, though, gatsby-theme-blog
does not feed that data into the MDXRenderer
.
You could shadow relevant gatsby-theme-blog
source files (e.g. gatsby-theme-blog/src/components/post.js
) in a similar way to how I did that on my website with gatsby-theme-notes
:
Yes, it's a pain in the ass to do and nowhere near as convenient as a ready-made plugin.
Here's an article about migrating Remark to MDX: https://www.gatsbyjs.com/docs/how-to/routing/migrate-remark-to-mdx/
However, converting the gatsby-remark-table-of-contents
plugin to MDX and making it supported by gatsby-theme
plugins would be a non-trivial task, due to the fact that their rendering architecture is completely different from what is typical for Remark-based pages.
@windmaomao I don't know your theme but did you do the config according to https://github.com/signalwerk/gatsby-remark-table-of-contents#global-configuration