Skip to content

Commit 8bbe7fb

Browse files
committed
Add 2022 posts
1 parent aad1e6b commit 8bbe7fb

16 files changed

+159
-6
lines changed

package-lock.json

Lines changed: 76 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"dependencies": {
1717
"@astrojs/check": "^0.9.3",
1818
"@astrojs/rss": "^4.0.7",
19+
"@giscus/react": "^3.0.0",
1920
"@resvg/resvg-js": "^2.6.2",
2021
"astro": "^4.16.3",
2122
"fuse.js": "^7.0.0",

src/components/Comments.tsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import Giscus, { type Theme } from "@giscus/react";
2+
import { GISCUS } from "@config";
3+
import { useEffect, useState } from "react";
4+
5+
interface CommentsProps {
6+
lightTheme?: Theme;
7+
darkTheme?: Theme;
8+
}
9+
10+
export default function Comments({
11+
lightTheme = "light",
12+
darkTheme = "dark",
13+
}: CommentsProps) {
14+
const [theme, setTheme] = useState(() => {
15+
const currentTheme = localStorage.getItem("theme");
16+
const browserTheme = window.matchMedia("(prefers-color-scheme: dark)")
17+
.matches
18+
? "dark"
19+
: "light";
20+
21+
return currentTheme || browserTheme;
22+
});
23+
24+
useEffect(() => {
25+
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
26+
const handleChange = ({ matches }: MediaQueryListEvent) => {
27+
setTheme(matches ? "dark" : "light");
28+
};
29+
30+
mediaQuery.addEventListener("change", handleChange);
31+
32+
return () => mediaQuery.removeEventListener("change", handleChange);
33+
}, []);
34+
35+
useEffect(() => {
36+
const themeButton = document.querySelector("#theme-btn");
37+
const handleClick = () => {
38+
setTheme(prevTheme => (prevTheme === "dark" ? "light" : "dark"));
39+
};
40+
41+
themeButton?.addEventListener("click", handleClick);
42+
43+
return () => themeButton?.removeEventListener("click", handleClick);
44+
}, []);
45+
46+
return (
47+
<div className="mt-8">
48+
<Giscus theme={theme === "light" ? lightTheme : darkTheme} {...GISCUS} />
49+
</div>
50+
);
51+
}

src/config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Site, SocialObjects } from "./types";
2+
import type { GiscusProps } from "@giscus/react";
23

34
export const SITE: Site = {
45
website: "https://emeraldjava.github.io/", // replace this with your deployed domain
@@ -45,3 +46,16 @@ export const SOCIALS: SocialObjects = [
4546
active: true,
4647
},
4748
];
49+
50+
export const GISCUS: GiscusProps = {
51+
repo: "[ENTER REPO HERE]",
52+
repoId: "[ENTER REPO ID HERE]",
53+
category: "[ENTER CATEGORY NAME HERE]",
54+
categoryId: "[ENTER CATEGORY ID HERE]",
55+
mapping: "pathname",
56+
reactionsEnabled: "0",
57+
emitMetadata: "0",
58+
inputPosition: "bottom",
59+
lang: "en",
60+
loading: "lazy",
61+
};
Loading

src/content/blog/2024/2024-06-22-GA.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ description: "Upgrade of Google Analytics tags"
1515
https://webreaper.dev/posts/astro-google-tag-manager-ga4/
1616

1717
https://tagmanager.google.com/#/container/accounts/6236586547/containers/188259084/workspaces/2
18+
19+
## update
20+
21+
Need to use is:inline to enable.

src/layouts/PostDetails.astro

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Datetime from "@components/Datetime";
77
import type { CollectionEntry } from "astro:content";
88
import { slugifyStr } from "@utils/slugify";
99
import ShareLinks from "@components/ShareLinks.astro";
10+
import Comments from "@components/Comments";
1011
import { SITE } from "@config";
1112
1213
export interface Props {
@@ -177,6 +178,18 @@ const nextPost =
177178
)
178179
}
179180
</div>
181+
182+
<!--
183+
https://github.com/giscus/giscus-component
184+
https://github.com/satnaing/astro-paper/blob/main/src/content/blog/how-to-integrate-giscus-comments.md -->
185+
<Comments client:only="react" />
186+
<!--<script async src="https://giscus.app/client.js"-->
187+
<!-- data-repo="[ENTER REPO HERE]"-->
188+
<!-- data-repo-id="[ENTER REPO ID HERE]"-->
189+
<!-- data-category="[ENTER CATEGORY NAME HERE]"-->
190+
<!-- data-category-id="[ENTER CATEGORY ID HERE]">-->
191+
<!--</script>-->
192+
180193
</main>
181194
<Footer />
182195
</Layout>

0 commit comments

Comments
 (0)