Skip to content

Commit cdd0be2

Browse files
authored
feat(giscus): expose language option for Comments component (#2012)
* add language support for Comment * docs: let users know they can customize their language preference
1 parent 9de370a commit cdd0be2

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

docs/features/comments.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ afterBody: [
4545
category: 'Announcements',
4646
// from data-category-id
4747
categoryId: 'DIC_kwDOFxRnmM4B-Xg6',
48+
// from data-lang
49+
lang: 'en'
4850
}
4951
}),
5052
],
@@ -90,6 +92,10 @@ type Options = {
9092
// where to put the comment input box relative to the comments
9193
// defaults to 'bottom'
9294
inputPosition?: "top" | "bottom"
95+
96+
// set your preference language here
97+
// defaults to 'en'
98+
lang?: string
9399
}
94100
}
95101
```

quartz/components/Comments.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Options = {
1717
strict?: boolean
1818
reactionsEnabled?: boolean
1919
inputPosition?: "top" | "bottom"
20+
lang?: string
2021
}
2122
}
2223

@@ -50,6 +51,7 @@ export default ((opts: Options) => {
5051
data-theme-url={
5152
opts.options.themeUrl ?? `https://${cfg.baseUrl ?? "example.com"}/static/giscus`
5253
}
54+
data-lang={opts.options.lang ?? "en"}
5355
></div>
5456
)
5557
}

quartz/components/scripts/comments.inline.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type GiscusElement = Omit<HTMLElement, "dataset"> & {
5555
strict: string
5656
reactionsEnabled: string
5757
inputPosition: "top" | "bottom"
58+
lang: string
5859
}
5960
}
6061

@@ -78,7 +79,7 @@ document.addEventListener("nav", () => {
7879
giscusScript.setAttribute("data-strict", giscusContainer.dataset.strict)
7980
giscusScript.setAttribute("data-reactions-enabled", giscusContainer.dataset.reactionsEnabled)
8081
giscusScript.setAttribute("data-input-position", giscusContainer.dataset.inputPosition)
81-
82+
giscusScript.setAttribute("data-lang", giscusContainer.dataset.lang)
8283
const theme = document.documentElement.getAttribute("saved-theme")
8384
if (theme) {
8485
giscusScript.setAttribute("data-theme", getThemeUrl(getThemeName(theme)))

0 commit comments

Comments
 (0)