mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 19:32:32 +08:00
docs: update giscus integration guide for AstroPaper v5 (#472)
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
author: FjellOverflow
|
author: FjellOverflow
|
||||||
pubDatetime: 2024-07-25T11:11:53Z
|
pubDatetime: 2024-07-25T11:11:53Z
|
||||||
modDatetime: 2024-09-25T12:07:53Z
|
modDatetime: 2025-03-12T12:28:53Z
|
||||||
title: How to integrate Giscus comments into AstroPaper
|
title: How to integrate Giscus comments into AstroPaper
|
||||||
slug: how-to-integrate-giscus-comments
|
slug: how-to-integrate-giscus-comments
|
||||||
featured: false
|
featured: false
|
||||||
@@ -103,14 +103,14 @@ The embedded script tag in the layout is quite static, with the _Giscus_ configu
|
|||||||
Firstly, we are going to install the [React component](https://www.npmjs.com/package/@giscus/react) for _Giscus_:
|
Firstly, we are going to install the [React component](https://www.npmjs.com/package/@giscus/react) for _Giscus_:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm i @giscus/react
|
npm i @giscus/react && npx astro add react
|
||||||
```
|
```
|
||||||
|
|
||||||
Then we create a new `Comments.tsx` React component in `src/components`:
|
Then we create a new `Comments.tsx` React component in `src/components`:
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
import Giscus, { type Theme } from "@giscus/react";
|
import Giscus, { type Theme } from "@giscus/react";
|
||||||
import { GISCUS } from "@config";
|
import { GISCUS } from "@/config";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
interface CommentsProps {
|
interface CommentsProps {
|
||||||
@@ -190,12 +190,14 @@ Note that specifying a `theme` here will override the `lightTheme` and `darkThem
|
|||||||
To complete the process, add the new Comments component to `src/layouts/PostDetails.astro` (replacing the `script` tag from the previous step).
|
To complete the process, add the new Comments component to `src/layouts/PostDetails.astro` (replacing the `script` tag from the previous step).
|
||||||
|
|
||||||
```diff
|
```diff
|
||||||
+ import Comments from "@components/Comments";
|
+ import Comments from "@/components/Comments";
|
||||||
|
|
||||||
<ShareLinks />
|
<ShareLinks />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
+ <Comments client:only="react" />
|
+ <Comments client:only="react" />
|
||||||
|
|
||||||
|
<hr class="my-6 border-dashed" />
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
<Footer />
|
<Footer />
|
||||||
|
|||||||
Reference in New Issue
Block a user