Skip to content

Commit 041f5bf

Browse files
committed
feat: 支持评论
1 parent dcd943a commit 041f5bf

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@floating-ui/dom": "^1.6.11",
1919
"@floating-ui/react": "^0.26.25",
2020
"@floating-ui/react-dom": "^2.1.2",
21+
"@giscus/react": "^3.1.0",
2122
"@iconify-json/material-symbols": "^1.2.4",
2223
"@iconify-json/mingcute": "^1.2.1",
2324
"@next/bundle-analyzer": "^14.2.15",

pnpm-lock.yaml

+64
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/(app)/notes/[nid]/page.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { type PostItem as PostItemType, getPostData } from '@/core';
1515
import { LayoutRightSidePortal } from '@/providers/shared/LayoutRightSideProvider';
1616
import { ArticleRightAside } from '@/components/modules/shared/ArticleRightAside';
1717
import { Signature } from '@/components/modules/shared/signature';
18+
import Gisus from '@/components/modules/comment/Giscus';
1819

1920
const { postDataMap } = await getPostData();
2021

@@ -64,6 +65,7 @@ export default async function Page({ params }: { params: Record<string, any> })
6465
<PaperLayout>
6566
<PageInner postData={postData} />
6667
</PaperLayout>
68+
<Gisus />
6769
</PageTransition>
6870
);
6971
}
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use client';
2+
3+
import { useEffect, useState } from 'react';
4+
import Giscus from '@giscus/react';
5+
import { useTheme } from 'next-themes';
6+
7+
export default function GS() {
8+
const { theme, systemTheme } = useTheme();
9+
const [resolvedTheme, setResolvedTheme] = useState<'light' | 'dark'>('light');
10+
11+
useEffect(() => {
12+
if (theme === 'system') {
13+
setResolvedTheme(
14+
systemTheme ??
15+
(window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'),
16+
);
17+
} else {
18+
setResolvedTheme(theme as 'light' | 'dark');
19+
}
20+
}, [theme, systemTheme]);
21+
22+
return (
23+
<div className="mt-16">
24+
<Giscus
25+
id="comments"
26+
repo="coderz-w/blog"
27+
repoId="R_kgDOMhALnA"
28+
category="Announcements"
29+
categoryId="DIC_kwDOMhALnM4CpMFu"
30+
mapping="pathname"
31+
term=""
32+
reactionsEnabled="1"
33+
emitMetadata="0"
34+
inputPosition="bottom"
35+
theme={resolvedTheme}
36+
lang="en"
37+
loading="lazy"
38+
/>
39+
</div>
40+
);
41+
}

src/styles/index.css

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
@import url(./mdContainer.css);
1212

1313
@import url(./theme.css);
14+

0 commit comments

Comments
 (0)