Skip to content

Commit a1dbb71

Browse files
Update Giscus component and add language filter for essays
1 parent df5a701 commit a1dbb71

File tree

9 files changed

+72
-14
lines changed

9 files changed

+72
-14
lines changed

src/components/Giscus.astro

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
---
22
interface Props {
3-
category: string;
4-
categoryId: string;
3+
category: "essays" | "inspirations" | "journals" | "lessons" | "questions";
54
}
65
7-
const { category, categoryId } = Astro.props;
6+
const { category } = Astro.props;
87
9-
// Get these values from https://giscus.app after configuring
108
const REPO = "ComputelessComputer/part-of-my-brain";
11-
const REPO_ID = ""; // TODO: Get from giscus.app
9+
const REPO_ID = "R_kgDOQyThnQ";
10+
11+
const CATEGORY_IDS: Record<string, string> = {
12+
essays: "DIC_kwDOQyThnc4C0ehA",
13+
inspirations: "DIC_kwDOQyThnc4C0ehC",
14+
journals: "DIC_kwDOQyThnc4C0eg4",
15+
lessons: "DIC_kwDOQyThnc4C0ehD",
16+
questions: "DIC_kwDOQyThnc4C0ehE",
17+
};
18+
19+
const categoryId = CATEGORY_IDS[category];
1220
---
1321

1422
<section class="giscus-container">
@@ -23,7 +31,7 @@ const REPO_ID = ""; // TODO: Get from giscus.app
2331
data-reactions-enabled="1"
2432
data-emit-metadata="0"
2533
data-input-position="top"
26-
data-theme="light"
34+
data-theme="preferred_color_scheme"
2735
data-lang="en"
2836
data-loading="lazy"
2937
crossorigin="anonymous"

src/content.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const essays = defineCollection({
99
updated_at: z.coerce.date().optional(),
1010
published: z.boolean().default(false),
1111
tags: z.array(z.string()).optional(),
12+
lang: z.enum(["en", "ko"]).default("en"),
1213
}),
1314
});
1415

src/pages/essays/[id].astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ const date = essay.data.created_at.toLocaleDateString("en-US", {
4242
</div>
4343
</article>
4444

45-
<Giscus category="Essays" categoryId="" />
45+
<Giscus category="essays" />
4646
</Base>

src/pages/essays/index.astro

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@ const sortedEssays = essays.sort((a, b) =>
1515

1616
<h1>Essays</h1>
1717

18-
<ul style="margin-top: 2rem;">
18+
<div style="margin: 1rem 0;">
19+
<button class="lang-btn active" data-lang="all">All</button>
20+
<button class="lang-btn" data-lang="en">English</button>
21+
<button class="lang-btn" data-lang="ko">Korean</button>
22+
</div>
23+
24+
<ul style="margin-top: 2rem;" id="essays-list">
1925
{sortedEssays.map((essay) => (
20-
<li style="margin-bottom: 1rem;">
26+
<li style="margin-bottom: 1rem;" data-lang={essay.data.lang}>
2127
<a href={`/essays/${essay.id}`}>{essay.data.title}</a>
28+
{essay.data.lang === "ko" && <span style="color: #999; margin-left: 0.5rem;">🇰🇷</span>}
2229
<br />
2330
<small style="color: #666;">
2431
{essay.data.created_at.toLocaleDateString("en-US", {
@@ -31,3 +38,45 @@ const sortedEssays = essays.sort((a, b) =>
3138
))}
3239
</ul>
3340
</Base>
41+
42+
<style>
43+
.lang-btn {
44+
background: none;
45+
border: 1px solid #ccc;
46+
padding: 0.25rem 0.75rem;
47+
margin-right: 0.5rem;
48+
cursor: pointer;
49+
border-radius: 4px;
50+
}
51+
.lang-btn:hover {
52+
background: #f0f0f0;
53+
}
54+
.lang-btn.active {
55+
background: #1a1a1a;
56+
color: white;
57+
border-color: #1a1a1a;
58+
}
59+
</style>
60+
61+
<script>
62+
const buttons = document.querySelectorAll('.lang-btn');
63+
const items = document.querySelectorAll('#essays-list li');
64+
65+
buttons.forEach(btn => {
66+
btn.addEventListener('click', () => {
67+
const lang = btn.getAttribute('data-lang');
68+
69+
buttons.forEach(b => b.classList.remove('active'));
70+
btn.classList.add('active');
71+
72+
items.forEach(item => {
73+
const itemLang = item.getAttribute('data-lang');
74+
if (lang === 'all' || itemLang === lang) {
75+
(item as HTMLElement).style.display = '';
76+
} else {
77+
(item as HTMLElement).style.display = 'none';
78+
}
79+
});
80+
});
81+
});
82+
</script>

src/pages/inspirations/[id].astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ const date = inspiration.data.created_at.toLocaleDateString("en-US", {
5454
</div>
5555
</article>
5656

57-
<Giscus category="Inspirations" categoryId="" />
57+
<Giscus category="inspirations" />
5858
</Base>

src/pages/journals/[id].astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ const date = new Date(dateStr).toLocaleDateString("en-US", {
3838
</div>
3939
</article>
4040

41-
<Giscus category="Journals" categoryId="" />
41+
<Giscus category="journals" />
4242
</Base>

src/pages/lessons/[id].astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ const date = lesson.data.created_at.toLocaleDateString("en-US", {
4444
</div>
4545
</article>
4646

47-
<Giscus category="Lessons" categoryId="" />
47+
<Giscus category="lessons" />
4848
</Base>

src/pages/questions/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ import Giscus from "../../components/Giscus.astro";
1414
Ask me anything. Sign in with GitHub to submit a question.
1515
</p>
1616

17-
<Giscus category="Questions" categoryId="" />
17+
<Giscus category="questions" />
1818
</Base>

0 commit comments

Comments
 (0)