Skip to content

Commit 0a5b969

Browse files
committed
feat: comments
1 parent ff6e579 commit 0a5b969

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

src/components/Comments.astro

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
3+
---
4+
5+
<script
6+
is:inline
7+
src="https://giscus.app/client.js"
8+
data-repo="FireIsGood/fireis.dev"
9+
data-repo-id="R_kgDOLy6p6g"
10+
data-category="Announcements"
11+
data-category-id="DIC_kwDOLy6p6s4ClW6P"
12+
data-mapping="pathname"
13+
data-strict="0"
14+
data-reactions-enabled="1"
15+
data-emit-metadata="0"
16+
data-input-position="bottom"
17+
data-theme="light"
18+
data-lang="en"
19+
data-loading="lazy"
20+
crossorigin="anonymous"
21+
async></script>
22+
23+
<script is:inline>
24+
function updateGiscusTheme() {
25+
const themeMapping = {
26+
light: "light",
27+
dark: "dark_dimmed",
28+
};
29+
const theme = themeMapping[document.documentElement.getAttribute("data-theme")];
30+
const iframe = document.querySelector("iframe.giscus-frame");
31+
if (!iframe) return;
32+
iframe.contentWindow.postMessage({ giscus: { setConfig: { theme } } }, "https://giscus.app");
33+
}
34+
35+
// Update if the theme changes
36+
const observer = new MutationObserver(updateGiscusTheme);
37+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
38+
39+
// Abuse the message passing system to force the theme to match at all times
40+
function handleMessage(event) {
41+
if (event.origin !== "https://giscus.app") return;
42+
if (!(typeof event.data === "object" && event.data.giscus)) return;
43+
44+
const giscusData = event.data.giscus;
45+
46+
// Ignore message and use this to force the theme to work for the first message
47+
updateGiscusTheme();
48+
}
49+
50+
// Attach listeners
51+
document.addEventListener("DOMContentLoaded", updateGiscusTheme);
52+
53+
window.addEventListener("message", handleMessage);
54+
</script>

src/layouts/BlogPost.astro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
import type { CollectionEntry } from "astro:content";
33
import Layout from "@/layouts/Layout.astro";
4+
import Comments from "@/components/Comments.astro";
45
import FormattedDate from "@/components/FormattedDate.astro";
56
import TableOfContents from "@/components/TableOfContents.astro";
67
import Breadcrumb from "@/components/Breadcrumb.astro";
@@ -54,6 +55,7 @@ const titlePrefixed = `FireIsBlog - ${title}`;
5455
<TableOfContents headings={props.headings} />
5556
<slot />
5657
</article>
58+
<Comments />
5759
<Ending />
5860
</Layout>
5961

src/styles/global.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,8 @@ a:has(.header-permalink) {
209209
.expressive-code {
210210
margin-bottom: var(--pico-typography-spacing-vertical);
211211
}
212+
213+
/* Giscus */
214+
.giscus {
215+
padding-inline: 1rem;
216+
}

0 commit comments

Comments
 (0)