mirror of
https://github.com/barkstone2/vault-to-blog.git
synced 2026-07-22 05:21:19 +00:00
feat: Add comments layout for post comments
This commit is contained in:
parent
790c0be51c
commit
db9be2269c
2 changed files with 34 additions and 0 deletions
|
|
@ -40,6 +40,7 @@ function MarkdownContent() {
|
|||
<div className="markdown-preview-sizer markdown-preview-section"
|
||||
dangerouslySetInnerHTML={{__html: innerHtml.content}}>
|
||||
</div>
|
||||
<UtterancesComments />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
33
react-app/src/components/UtterancesComments.jsx
Normal file
33
react-app/src/components/UtterancesComments.jsx
Normal 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;
|
||||
Loading…
Reference in a new issue