From db9be2269c137e123e4b2fcc23f2bff7aebc8b32 Mon Sep 17 00:00:00 2001 From: barkstone Date: Mon, 9 Dec 2024 21:25:38 +0900 Subject: [PATCH] feat: Add comments layout for post comments --- react-app/src/components/MarkdownContent.jsx | 1 + .../src/components/UtterancesComments.jsx | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 react-app/src/components/UtterancesComments.jsx diff --git a/react-app/src/components/MarkdownContent.jsx b/react-app/src/components/MarkdownContent.jsx index 16038f4..2b1ea7a 100644 --- a/react-app/src/components/MarkdownContent.jsx +++ b/react-app/src/components/MarkdownContent.jsx @@ -40,6 +40,7 @@ function MarkdownContent() {
+ ); } diff --git a/react-app/src/components/UtterancesComments.jsx b/react-app/src/components/UtterancesComments.jsx new file mode 100644 index 0000000..9155235 --- /dev/null +++ b/react-app/src/components/UtterancesComments.jsx @@ -0,0 +1,33 @@ +import {useEffect, useRef} from "react"; +import data from '../stores/data.json' + +const UtterancesComments = () => { + const commentsRef = useRef(null); + + useEffect(() => { + if (!data.isEnableComments) return; + const currentRef = commentsRef.current; + if (!currentRef) return; + + const script = document.createElement("script"); + script.src = "https://utteranc.es/client.js"; + script.setAttribute("repo", data.repo); + script.setAttribute("issue-term", "pathname"); + script.setAttribute("theme", data.theme); + script.crossOrigin = "anonymous"; + script.async = true; + + commentsRef.current.appendChild(script); + + return () => { + if (commentsRef) { + currentRef.innerHTML = ""; + } + }; + + }, []); + + return
; +}; + +export default UtterancesComments; \ No newline at end of file