|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { useEffect, useRef } from "react"; |
| 4 | + |
| 5 | +export function GiscusComments() { |
| 6 | + const containerRef = useRef<HTMLDivElement>(null); |
| 7 | + |
| 8 | + useEffect(() => { |
| 9 | + const container = containerRef.current; |
| 10 | + if (!container) { |
| 11 | + return; |
| 12 | + } |
| 13 | + |
| 14 | + const script = document.createElement("script"); |
| 15 | + script.src = "https://giscus.app/client.js"; |
| 16 | + script.async = true; |
| 17 | + script.crossOrigin = "anonymous"; |
| 18 | + script.setAttribute("data-repo", "InvolutionHell/involutionhell.github.io"); |
| 19 | + script.setAttribute("data-repo-id", "R_kgDOPuD_8A"); |
| 20 | + script.setAttribute("data-category", "Comments"); |
| 21 | + script.setAttribute("data-category-id", "DIC_kwDOPuD_8M4Cvip8"); |
| 22 | + script.setAttribute("data-mapping", "pathname"); |
| 23 | + script.setAttribute("data-strict", "0"); |
| 24 | + script.setAttribute("data-reactions-enabled", "1"); |
| 25 | + script.setAttribute("data-emit-metadata", "0"); |
| 26 | + script.setAttribute("data-input-position", "bottom"); |
| 27 | + script.setAttribute("data-theme", "preferred_color_scheme"); |
| 28 | + script.setAttribute("data-lang", "en"); |
| 29 | + |
| 30 | + container.appendChild(script); |
| 31 | + |
| 32 | + return () => { |
| 33 | + while (container.firstChild) { |
| 34 | + container.removeChild(container.firstChild); |
| 35 | + } |
| 36 | + }; |
| 37 | + }, []); |
| 38 | + |
| 39 | + return <div ref={containerRef} className="giscus" />; |
| 40 | +} |
0 commit comments