Skip to content

Commit 92b00ba

Browse files
committed
✨ feat: add comment section with giscus
Follow the process mentions in [this doc](https://rikublock.dev/docs/tutorials/giscus-integration/), I added comment sections for blog and doc pages using giscus. All the comments and reactions are stored in GitHub discussion under category "Giscus".
1 parent 53ac284 commit 92b00ba

File tree

7 files changed

+7926
-7731
lines changed

7 files changed

+7926
-7731
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,12 @@ If you're not familiar with creating pull requests but want to contribute, you c
7070

7171
We appreciate all contributions to making the Open-LLM-VTuber documentation better!
7272

73+
74+
75+
## Managing Giscus Comments When Renaming or Moving Pages
76+
77+
We use Giscus to enable the comment section on the website. All comments and reactions are stored in this repository's GitHub Discussions under the "Page Comments" category.
78+
79+
Giscus relies on the page path to associate comments with the correct page. If you change a page's path or filename, the comments may no longer appear because Giscus won't find them.
80+
81+
To prevent this, you must also update the title of the corresponding GitHub Discussion to match the new page path or filename.

package-lock.json

Lines changed: 69 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@docusaurus/preset-classic": "^3.7.0",
2323
"@docusaurus/theme-mermaid": "^3.7.0",
2424
"@docusaurus/theme-search-algolia": "^3.7.0",
25+
"@giscus/react": "^3.1.0",
2526
"clsx": "^2.0.0",
2627
"posthog-docusaurus": "^2.0.4",
2728
"prism-react-renderer": "^2.3.0",

src/components/Comments/index.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
import Giscus from "@giscus/react";
3+
import { useColorMode } from '@docusaurus/theme-common';
4+
5+
export default function Comments() {
6+
const { colorMode } = useColorMode();
7+
8+
9+
return (
10+
<Giscus
11+
id="comments"
12+
repo="Open-LLM-VTuber/open-llm-vtuber.github.io"
13+
repoId="R_kgDOMeM4rg"
14+
category="Page Comments"
15+
categoryId="DIC_kwDOMeM4rs4Ctub5"
16+
mapping="pathname"
17+
strict="0"
18+
term="Welcome to @giscus/react component!"
19+
reactionsEnabled="1"
20+
emitMetadata="0"
21+
inputPosition="top"
22+
theme="catppuccin_latte"
23+
lang="en"
24+
loading="eager"
25+
/>
26+
);
27+
}

src/theme/BlogPostItem/index.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
import BlogPostItem from "@theme-original/BlogPostItem";
3+
import type BlogPostItemType from "@theme/BlogPostItem";
4+
import type { WrapperProps } from "@docusaurus/types";
5+
import { useBlogPost } from "@docusaurus/plugin-content-blog/client";
6+
import Comments from "@site/src/components/Comments";
7+
8+
type Props = WrapperProps<typeof BlogPostItemType>;
9+
10+
export default function BlogPostItemWrapper(props: Props): JSX.Element {
11+
const { metadata, isBlogPostPage } = useBlogPost();
12+
const { comments = true } = metadata.frontMatter;
13+
14+
return (
15+
<>
16+
<BlogPostItem {...props} />
17+
{comments && isBlogPostPage && <Comments />}
18+
</>
19+
);
20+
}

src/theme/DocItem/Footer/index.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
import DocItemFooter from "@theme-original/DocItem/Footer";
3+
import type DocItemFooterType from "@theme/DocItem/Footer";
4+
import type { WrapperProps } from "@docusaurus/types";
5+
import { useDoc } from "@docusaurus/plugin-content-docs/client";
6+
import Comments from "@site/src/components/Comments";
7+
8+
type Props = WrapperProps<typeof DocItemFooterType>;
9+
10+
export default function DocItemFooterWrapper(props: Props): JSX.Element {
11+
const { metadata } = useDoc();
12+
const { comments = true } = metadata.frontMatter;
13+
14+
return (
15+
<>
16+
<DocItemFooter {...props} />
17+
{comments && <Comments />}
18+
</>
19+
);
20+
}

0 commit comments

Comments
 (0)