feat: Add comments layout for post comments

This commit is contained in:
barkstone 2024-12-09 21:25:38 +09:00 committed by barkstone2
parent 790c0be51c
commit db9be2269c
2 changed files with 34 additions and 0 deletions

View file

@ -40,6 +40,7 @@ function MarkdownContent() {
<div className="markdown-preview-sizer markdown-preview-section"
dangerouslySetInnerHTML={{__html: innerHtml.content}}>
</div>
<UtterancesComments />
</>
);
}

View file

@ -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 <div ref={commentsRef} />;
};
export default UtterancesComments;