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
How can I extract TableOfContents of each post and set this component in markdown file ? #24469
Comments
Thank you for opening this! The problem with your current approach is that your I think you have two options:
We're marking this issue as answered and closing it for now but please feel free to comment here if you would like to continue this discussion. We also recommend heading over to our communities if you have questions that are not bug reports or feature requests. We hope we managed to help and thank you for using Gatsby! |
Hi @LekoArts Because I would like to insert ToC in any place I would like to have in markdown file, I guess I need to use MDX in that case. (Option1 that you mentioned looks good, but I think I can only show the ToC component above the other content of the post if I apply this method) As per the page below, I created TableOfContents component and try to use it in mdx file. But, now, I got another issue that I don't see mdx post in my blog's top page. Would you please support me how to show mdx post in blog's top page ? What I have done is here so far;
And here is my code/src/templates/post-template.jsx
/src/components/TableOfContents/index.jsx
/src/pages/articles/2020-05-25--TableOfContents/index.mdx
Thanks again for your support ! |
Finally, I got it work in a way that I would like to achieve, showing "Table of Contents" in markdown file wherever I want. Here are brief explanation.
|
Hello all,
I would like to show table of contents of each post in each post, by using Component in markdown file.
However, I can not extract specific "table of contents" for each post.
Can anybody support me to get the corresponding "table of contents" for each post ?
Current Result
In a post, I could display "table of contents", but this is the "table of contents" of 1st set under
allMarkdownRemark/edges/node
, and not the one from the post, which I would like to get the "table of contents" from.Post
sorry that it's Japanese. Basically, the blue highlighted characters are the list from table of contents.
Graphql
What I would like to achieve
In this post example, I would like to show the below "table of contents" as this is the one which is the table of content of the post that I display.
What I have done so far
src/templates/post-template.jsx
, I added tableOfContents in graphqlsrc/components/PostTemplateDetails/index.jsx
, and use renderAst to make it possible to be used in markdown file<tableofcontents></tableofcontents>
in markdown fileHere are my codes
/src/templates/post-templates.jsx
/src/components/TableOfContents/index.jsx
/src/components/PostTemplateDetails
/src/pages/articles/2020-05-25--TableOfContents/index.md
thanks a lot for your support and looking forward to hearing any advise !!!
The text was updated successfully, but these errors were encountered: