Skip to content

Commit d560b64

Browse files
authored
Merge pull request #179 from InvolutionHell/feat/longsizhuo/giscus2docId
feat: 为GiscusComments添加 docId 属性
2 parents ec1ecca + 346b9a2 commit d560b64

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

app/components/GiscusComments.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
'use client';
1+
"use client";
22

3-
import Giscus from '@giscus/react';
3+
import Giscus from "@giscus/react";
44

55
interface GiscusCommentsProps {
66
className?: string;
7+
docId?: string | null;
78
}
89

9-
export function GiscusComments({ className }: GiscusCommentsProps) {
10+
export function GiscusComments({ className, docId }: GiscusCommentsProps) {
11+
const useDocId = typeof docId === "string" && docId.trim().length > 0;
12+
1013
return (
1114
<div className={className}>
1215
<Giscus
1316
repo="InvolutionHell/involutionhell.github.io"
1417
repoId="R_kgDOPuD_8A"
1518
category="Comments"
1619
categoryId="DIC_kwDOPuD_8M4Cvip8"
17-
mapping="pathname"
20+
mapping={useDocId ? "specific" : "pathname"}
21+
term={useDocId ? docId : undefined}
1822
strict="0"
1923
reactionsEnabled="1"
2024
emitMetadata="0"

app/docs/[...slug]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default async function DocPage({ params }: Param) {
8686
<Mdx components={getMDXComponents()} />
8787
<Contributors entry={contributorsEntry} />
8888
<section className="mt-16">
89-
<GiscusComments />
89+
<GiscusComments docId={docIdFromPage ?? null} />
9090
</section>
9191
</DocsBody>
9292
</DocsPage>

0 commit comments

Comments
 (0)