feat: split giscus to local-provided standalone component

This commit is contained in:
草师傅 2025-07-21 16:21:39 +08:00
parent 05a0f3461d
commit 5adf3bc560
Signed by: gb
GPG key ID: 43330A030E2D6478
5 changed files with 80 additions and 19 deletions

View file

@ -19,6 +19,7 @@
"@fontsource-variable/jetbrains-mono": "^5.2.5",
"artalk": "^2.9.1",
"astro": "^5.2.5",
"giscus": "^1.6.0",
"ico-endec": "^0.1.6",
"katex": "^0.16.22",
"rehype-katex": "^7.0.1",

52
pnpm-lock.yaml generated
View file

@ -32,6 +32,9 @@ importers:
astro:
specifier: ^5.2.5
version: 5.7.10(@azure/identity@4.9.1)(@types/node@22.15.3)(rollup@4.40.1)(typescript@5.8.3)(yaml@2.7.1)
giscus:
specifier: ^1.6.0
version: 1.6.0
ico-endec:
specifier: ^0.1.6
version: 0.1.6
@ -798,6 +801,12 @@ packages:
'@jridgewell/trace-mapping@0.3.9':
resolution: {integrity: sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==}
'@lit-labs/ssr-dom-shim@1.4.0':
resolution: {integrity: sha512-ficsEARKnmmW5njugNYKipTm4SFnbik7CXtoencDZzmzo/dQ+2Q0bgkzJuoJP20Aj0F+izzJjOqsnkd6F/o1bw==}
'@lit/reactive-element@2.1.1':
resolution: {integrity: sha512-N+dm5PAYdQ8e6UlywyyrgI2t++wFGXfHx+dSJ1oBrg6FAxUj40jId++EaRm80MKX5JnlH1sBsyZ5h0bcZKemCg==}
'@mdx-js/mdx@3.1.0':
resolution: {integrity: sha512-/QxEhPAvGwbQmy1Px8F899L5Uc2KZ6JtXwlCgJmjSTBedwOZkByYcBG4GceIGPXRDsmfxhHazuS+hlOShRLeDw==}
@ -1037,6 +1046,9 @@ packages:
'@types/tmp@0.0.33':
resolution: {integrity: sha512-gVC1InwyVrO326wbBZw+AO3u2vRXz/iRWq9jYhpG4W8LXyIgDv3ZmcLQ5Q4Gs+gFMyqx+viFoFT+l3p61QFCmQ==}
'@types/trusted-types@2.0.7':
resolution: {integrity: sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==}
'@types/unist@2.0.11':
resolution: {integrity: sha512-CmBKiL6NNo/OqgmMn95Fk9Whlp2mtvIv+KNpQKN2F4SjvrEesubTRWGYSg+BnWZOnlCaSTU1sMpsBOzgbYhnsA==}
@ -1747,6 +1759,9 @@ packages:
resolution: {integrity: sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==}
engines: {node: '>=10'}
giscus@1.6.0:
resolution: {integrity: sha512-Zrsi8r4t1LVW950keaWcsURuZUQwUaMKjvJgTCY125vkW6OiEBkatE7ScJDbpqKHdZwb///7FVC21SE3iFK3PQ==}
github-from-package@0.0.0:
resolution: {integrity: sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==}
@ -2053,6 +2068,15 @@ packages:
resolution: {integrity: sha512-7W0vV3rqv5tokqkBAFV1LbR7HPOWzXQDpDgEuib/aJ1jsZZx6x3c2mBI+TJhJzOhkGeaLbCKEHXEXLfirtG2JA==}
engines: {node: '>=18'}
lit-element@4.2.1:
resolution: {integrity: sha512-WGAWRGzirAgyphK2urmYOV72tlvnxw7YfyLDgQ+OZnM9vQQBQnumQ7jUJe6unEzwGU3ahFOjuz1iz1jjrpCPuw==}
lit-html@3.3.1:
resolution: {integrity: sha512-S9hbyDu/vs1qNrithiNyeyv64c9yqiW9l+DBgI18fL+MTvOtWoFR0FWiyq1TxaYef5wNlpEmzlXoBlZEO+WjoA==}
lit@3.3.1:
resolution: {integrity: sha512-Ksr/8L3PTapbdXJCk+EJVB78jDodUMaP54gD24W186zGRARvwrsPfS60wae/SSCTCNZVPd1chXqio1qHQmu4NA==}
lodash.includes@4.3.0:
resolution: {integrity: sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==}
@ -4024,6 +4048,12 @@ snapshots:
'@jridgewell/resolve-uri': 3.1.2
'@jridgewell/sourcemap-codec': 1.5.0
'@lit-labs/ssr-dom-shim@1.4.0': {}
'@lit/reactive-element@2.1.1':
dependencies:
'@lit-labs/ssr-dom-shim': 1.4.0
'@mdx-js/mdx@3.1.0(acorn@8.14.1)':
dependencies:
'@types/estree': 1.0.7
@ -4261,6 +4291,8 @@ snapshots:
'@types/tmp@0.0.33': {}
'@types/trusted-types@2.0.7': {}
'@types/unist@2.0.11': {}
'@types/unist@3.0.3': {}
@ -5058,6 +5090,10 @@ snapshots:
get-stream@6.0.1: {}
giscus@1.6.0:
dependencies:
lit: 3.3.1
github-from-package@0.0.0: {}
github-slugger@2.0.0: {}
@ -5466,6 +5502,22 @@ snapshots:
dependencies:
package-json: 10.0.1
lit-element@4.2.1:
dependencies:
'@lit-labs/ssr-dom-shim': 1.4.0
'@lit/reactive-element': 2.1.1
lit-html: 3.3.1
lit-html@3.3.1:
dependencies:
'@types/trusted-types': 2.0.7
lit@3.3.1:
dependencies:
'@lit/reactive-element': 2.1.1
lit-element: 4.2.1
lit-html: 3.3.1
lodash.includes@4.3.0: {}
lodash.isboolean@3.0.3: {}

View file

@ -3,10 +3,10 @@ import {siteConfig} from "../config";
import FediverseComments from "./helper/comments/Fediverse.astro";
import HatsuComments from "./helper/comments/Hatsu.astro";
import Artalk from "./helper/comments/Artalk.astro";
import Giscus from "./helper/comments/Giscus.astro";
const method = siteConfig.comments.type
const giscusConfig = siteConfig.comments.giscus
const FediverseConfig = siteConfig.comments.fediverse
interface Props {
path?: string;
@ -15,24 +15,7 @@ interface Props {
let { path='/' } = Astro.props;
---
{method === 'artalk' && <Artalk path={path} />}
{method === 'giscus' && (
<script
src="https://giscus.app/client.js"
data-repo={giscusConfig.repo}
data-repo-id={giscusConfig.repoId}
data-category={giscusConfig.category}
data-category-id={giscusConfig.categoryId}
data-mapping={giscusConfig.mapping}
data-strict={giscusConfig.strict}
data-reactions-enabled={giscusConfig.reactionsEnabled}
data-emit-metadata={giscusConfig.emitMetadata}
data-input-position={giscusConfig.inputPosition}
data-theme={giscusConfig.theme}
data-lang={giscusConfig.lang}
crossorigin="anonymous"
async
></script>
)}
{method === 'giscus' && <Giscus/>}
<!-- if prerender === true is set then render from client -->
{(method === 'fediverse' && !FediverseConfig.renderOnServer ) && <FediverseComments path={path} /> }
{(method === 'fediverse' && FediverseConfig.renderOnServer ) && <FediverseComments server:defer path={path} ><p>Loading comments...</p></FediverseComments> }

View file

@ -0,0 +1,24 @@
---
import {siteConfig} from "../../../config";
const giscusConfig = siteConfig.comments.giscus
---
<giscus-widget
repo={giscusConfig.repo}
repoid={giscusConfig.repoId}
category={giscusConfig.category}
categoryid={giscusConfig.categoryId}
mapping={giscusConfig.mapping}
strict={giscusConfig.strict}
term={giscusConfig.term}
reactionsEnabled={giscusConfig.reactionsEnabled}
emitMetadata={giscusConfig.emitMetadata}
inputPosition={giscusConfig.inputPosition}
theme={giscusConfig.theme}
lang={giscusConfig.lang}
crossorigin="anonymous"
loading="lazy"
></giscus-widget>
<script>
import 'giscus';
</script>

View file

@ -54,6 +54,7 @@ export const siteConfig = {
category:"[ENTER CATEGORY NAME HERE]",
categoryId:"[ENTER CATEGORY ID HERE]",
mapping:"pathname",
term: "Welcome to comment powered by @giscus",
strict:"0",
reactionsEnabled:"1",
emitMetadata:"0",