Skip to content

Commit

Permalink
Add giscus
Browse files Browse the repository at this point in the history
  • Loading branch information
winterjung committed Oct 31, 2024
1 parent bdef772 commit 22f5a58
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/components/giscus.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { useEffect, useRef } from 'react'

export default function Giscus() {
const containerRef = useRef(null)

useEffect(() => {
const script = document.createElement('script')
const giscusAttributes = {
src: "https://giscus.app/client.js",
"data-repo": "winterjung/blog",
"data-repo-id": "MDEwOlJlcG9zaXRvcnkyMzYyNTc3MDc=",
"data-category": "Comments",
"data-category-id": "DIC_kwDODhUBq84Cj2FN",
"data-mapping": "pathname",
"data-strict": "0",
"data-reactions-enabled": "1",
"data-emit-metadata": "0",
"data-input-position": "top",
"data-theme": "preferred_color_scheme",
"data-lang": "ko",
"data-loading": "lazy",
crossorigin: "anonymous",
async: true,
}

Object.entries(giscusAttributes).forEach(([key, value]) => {
script.setAttribute(key, value)
})

containerRef.current.appendChild(script)
return () => {
containerRef.current?.removeChild(script)
}
}, [])

return <div ref={containerRef} />
}
2 changes: 2 additions & 0 deletions src/templates/post.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { graphql } from "gatsby"
import React from "react"
import Giscus from "../components/Giscus"
import Layout from "../components/layout"
import Seo from "../components/seo"
import "../utils/typography"
Expand All @@ -18,6 +19,7 @@ export default function Post({ data }) {
<h1>{post.frontmatter.title}</h1>
<div dangerouslySetInnerHTML={{ __html: post.html }}></div>
</div>
<Giscus />
</Layout>
)
}
Expand Down

0 comments on commit 22f5a58

Please sign in to comment.