-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
Next.js SSG + markdown-it #346
Comments
Hey, thanks for opening this issue! Currently this may be possible using jsdom on the server, but isn't natively supported since tocbot uses the browsers DOM methods and those are not typically available server side. However, this is something I'd be open to supporting better, if you have ideas for how this could be improved I'd love to hear them. Can you tell me any more about your use case? Thanks! |
My use-case is quite generic. I am using Next.js to statically build a blog/portfolio site and I serve this on GitHub Pages. All the operations, from building page slugs to parsing markdown to HTML happens at the build time and I want to keep it that way for peace of mind 😄 and this approach ensures a faster loading experience for visitors as all content is pre-rendered and avoids any client-side processing for TOC generation. For example, I have this blog https://realchakrawarti.github.io/aham/blog/microdata-seo where content is parsed by markdown-it, and using one of its plugin I add the heading IDs for quick links. I want to generate the TOC at build time against the headings without adding a placeholder text to inject the TOC generated at runtime on like The way I am thinking is, the user will pass the HTML string, for example in the above code snippet This eliminates the need for placeholders in the markdown and allows for TOC insertion anywhere. My requirement is to add the TOC HTML inside an |
Thanks for the explanation! Is this a feature you would be interested in contributing to tocbot? |
Coming weekend, I would go over code once and see how I could go about making changes. If this ends up with quite a lot of changes and across files, would create a separate package altogether. Keeping this issue open for now. Will close it with an update in a week or two. Thanks :D |
Here is a quick utility I put together that handles SSR of the toc content that you could use at build time. |
Hi @tscanlin, I can see that #347 has been merged to the main branch but I didn't find any note on how Please do let me know if I am missing something. Thanks! |
Hey, I was planning to keep this separate from the main bundle since not all users may use it. |
Hey, I forgot to add this into the exports, but I just pushed a fix to add the src/js folder. If you install the latest version ( |
Hey, sorry for the delay in responding. Yeah, for now I'd say just install |
Again, thanks for supporting this. Really appreciate it. Feel free to close the issue 😊 |
Thank you for working with me on this! |
I am using Next.js for SSG with markdown-it. I have markown files on disk locally from which I generate the HTML string.
I want the TOC HTML string at build time with my custom class name attached to the parent for styling it.
The idea is to pass the result to a function for example tocify(result) => HTML TOC content
Is this something possible, if so then how? Thanks.
The text was updated successfully, but these errors were encountered: