Skip to content

Commit

Permalink
feat: utterances 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
wish0ne committed Dec 9, 2023
1 parent bef8386 commit 5286c72
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/components/Comments.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React, { createRef, useEffect } from "react";

export default function Comments() {
const containerRef = createRef<HTMLDivElement>();
useEffect(() => {
const utterances = document.createElement("script");
const attributes = {
src: "https://utteranc.es/client.js",
repo: "wish0ne/wish0ne.github.io",
"issue-term": "pathname",
label: "💬",
theme: "github-light",
crossOrigin: "anonymous",
async: "true",
};
Object.entries(attributes).forEach(([key, value]) => {
utterances.setAttribute(key, value);
});
containerRef.current?.appendChild(utterances);
}, []);
return <div id="comment" ref={containerRef} />;
}
2 changes: 2 additions & 0 deletions src/pages/posts/{mdx.frontmatter__slug}.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { graphql, PageProps } from "gatsby";
import { GatsbyImage, getImage, IGatsbyImageData } from "gatsby-plugin-image";
import { css } from "@emotion/react";
import Toc from "../../components/Toc";
import Comments from "../../components/Comments";

interface toc {
title: string;
Expand Down Expand Up @@ -206,6 +207,7 @@ const BlogPost = ({ data, children }: PageProps<DataProps>) => {
>
{children}
</main>
<Comments />
</div>
<Toc tableOfContents={data.mdx.tableOfContents} />
</div>
Expand Down

0 comments on commit 5286c72

Please sign in to comment.