Add Comments to Your Docusaurus Site
Comments, Reactions, and Ratings for Docs and Blog Posts
Your readers have questions, and your docs are where they ask them. Swizzle one theme component, add the Hyvor Talk React library, and every blog post (or doc page) gets a comment section.
Steps to Add Comments to Docusaurus
Before you start, sign up at the Hyvor Talk Console and add your website with your site's domain. Copy the website ID from Settings → Website.
Install the Hyvor Talk React library in your Docusaurus project:
npm install @hyvor/hyvor-talk-reactSwizzle the
BlogPostItemcomponent with the--wrapoption. This createssrc/theme/BlogPostItem/index.js.npm run swizzle @docusaurus/theme-classic BlogPostItem -- --wrapReplace the content of that file with the code below. The comments only render on the full post page, not in the blog list. Replace
YOUR_WEBSITE_IDwith your website ID.import React from 'react'; import BlogPostItem from '@theme-original/BlogPostItem'; import BrowserOnly from '@docusaurus/BrowserOnly'; import { useBlogPost } from '@docusaurus/plugin-content-blog/client'; import { Comments } from '@hyvor/hyvor-talk-react'; export default function BlogPostItemWrapper(props) { const { metadata, isBlogPostPage } = useBlogPost(); return ( <> <BlogPostItem {...props} /> {isBlogPostPage && ( <BrowserOnly> {() => ( <Comments website-id={YOUR_WEBSITE_ID} page-id={metadata.permalink} /> )} </BrowserOnly> )} </> ); }Run
npm startand open a blog post. The comment section shows up at the end.
Add comments to documentation pages
To show comments under each doc page as well, wrap DocItem/Footer:
npm run swizzle @docusaurus/theme-classic DocItem/Footer -- --wrapThen edit src/theme/DocItem/Footer/index.js:
import React from 'react';
import Footer from '@theme-original/DocItem/Footer';
import BrowserOnly from '@docusaurus/BrowserOnly';
import { useDoc } from '@docusaurus/plugin-content-docs/client';
import { Comments } from '@hyvor/hyvor-talk-react';
export default function FooterWrapper(props) {
const { metadata } = useDoc();
return (
<>
<Footer {...props} />
<BrowserOnly>
{() => <Comments website-id={YOUR_WEBSITE_ID} page-id={metadata.id} />}
</BrowserOnly>
</>
);
}The doc ID stays the same when you change the sidebar or URL, so each page keeps its thread.
That's it. Deploy your site and the comments are live. From the Console, you can match the colors to your Docusaurus theme.
Frequently asked questions
No. Docusaurus leaves comments to you. Swizzling lets you add Hyvor Talk to your theme without forking it, and the comments then show up on every blog post.
Swizzling copies a theme component into src/theme so you can change it. The --wrap option keeps the original component and only adds things around it, which is the safe kind of swizzle that survives Docusaurus updates. See the swizzling docs.
Docusaurus renders every page to HTML at build time. The comments load in the browser, so BrowserOnly keeps them out of the server build and avoids errors there.
Yes. Wrap DocItem/Footer the same way, and readers can comment, react, or rate each doc page. It's an easy way to find docs that need work. The steps are in the guide above.
You don't need a separate plugin. Our React library plus one wrapped theme component does the same thing, and you control where the comments show up.
Readers can ask questions right where they get stuck, and you get an email when they do. Spam filtering and moderation keep things tidy, and ratings show which pages people find helpful.
It's free to try for 14 days, no credit card needed. After that, see the pricing page.