-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(comments): add giscus for comments
- Loading branch information
1 parent
503341b
commit 8293f39
Showing
5 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Giscus, { type GiscusProps, type Theme } from "@giscus/react"; | ||
import { GISCUS } from "@config"; | ||
import { useState } from "react"; | ||
|
||
interface Props { | ||
lightTheme?: Theme; | ||
darkTheme?: Theme; | ||
} | ||
|
||
export default function Comments({ | ||
lightTheme = "light", | ||
darkTheme = "dark", | ||
}: Props) { | ||
const currentTheme = localStorage.getItem("theme"); | ||
const browserTheme = window.matchMedia("(prefers-color-scheme: dark)").matches | ||
? "dark" | ||
: "light"; | ||
|
||
const [theme, setTheme] = useState(currentTheme || browserTheme); | ||
|
||
// manual theme toggle | ||
document.querySelector("#theme-btn")?.addEventListener("click", () => { | ||
theme === "dark" ? setTheme("light") : setTheme("dark"); | ||
}); | ||
|
||
// browser preference | ||
window | ||
.matchMedia("(prefers-color-scheme: dark)") | ||
.addEventListener("change", ({ matches: isDark }) => { | ||
isDark ? setTheme("dark") : setTheme("light"); | ||
}); | ||
|
||
return ( | ||
<div className="mt-8"> | ||
<Giscus theme={theme === "light" ? lightTheme : darkTheme} {...GISCUS} /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters