mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-27 23:04:05 -06:00
feat(comments) allow passing themes to Giscus
This commit is contained in:
parent
3aa11357aa
commit
15370625a6
@ -63,6 +63,15 @@ type Options = {
|
|||||||
category: string
|
category: string
|
||||||
categoryId: string
|
categoryId: string
|
||||||
|
|
||||||
|
// defaults to 'https://giscus.app'
|
||||||
|
themeUrl?: string
|
||||||
|
|
||||||
|
// defaults to 'light'
|
||||||
|
lightTheme?: string
|
||||||
|
|
||||||
|
// defaults to 'dark'
|
||||||
|
darkTheme?: string
|
||||||
|
|
||||||
// how to map pages -> discussions
|
// how to map pages -> discussions
|
||||||
// defaults to 'url'
|
// defaults to 'url'
|
||||||
mapping?: "url" | "title" | "og:title" | "specific" | "number" | "pathname"
|
mapping?: "url" | "title" | "og:title" | "specific" | "number" | "pathname"
|
||||||
|
|||||||
@ -10,6 +10,9 @@ type Options = {
|
|||||||
repoId: string
|
repoId: string
|
||||||
category: string
|
category: string
|
||||||
categoryId: string
|
categoryId: string
|
||||||
|
themeUrl?: string
|
||||||
|
lightTheme?: string
|
||||||
|
darkTheme?: string
|
||||||
mapping?: "url" | "title" | "og:title" | "specific" | "number" | "pathname"
|
mapping?: "url" | "title" | "og:title" | "specific" | "number" | "pathname"
|
||||||
strict?: boolean
|
strict?: boolean
|
||||||
reactionsEnabled?: boolean
|
reactionsEnabled?: boolean
|
||||||
|
|||||||
@ -13,20 +13,45 @@ const changeTheme = (e: CustomEventMap["themechange"]) => {
|
|||||||
{
|
{
|
||||||
giscus: {
|
giscus: {
|
||||||
setConfig: {
|
setConfig: {
|
||||||
theme: theme,
|
theme: getThemeName(theme),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"https://giscus.app",
|
getThemeUrl(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getThemeName = (theme: "light" | "dark") => {
|
||||||
|
const giscusContainer = document.querySelector(".giscus") as GiscusElement
|
||||||
|
if (!giscusContainer) {
|
||||||
|
return theme
|
||||||
|
}
|
||||||
|
const darkGiscus =
|
||||||
|
giscusContainer.dataset.darkTheme !== "" ? giscusContainer.dataset.darkTheme : "dark"
|
||||||
|
const lightGiscus =
|
||||||
|
giscusContainer.dataset.lightTheme !== "" ? giscusContainer.dataset.lightTheme : "light"
|
||||||
|
return theme === "dark" ? darkGiscus : lightGiscus
|
||||||
|
}
|
||||||
|
|
||||||
|
const getThemeUrl = () => {
|
||||||
|
const giscusContainer = document.querySelector(".giscus") as GiscusElement
|
||||||
|
if (!giscusContainer) {
|
||||||
|
return "https://giscus.app"
|
||||||
|
}
|
||||||
|
return giscusContainer.dataset.themeUrl !== ""
|
||||||
|
? giscusContainer.dataset.themeUrl
|
||||||
|
: "https://giscus.app"
|
||||||
|
}
|
||||||
|
|
||||||
type GiscusElement = Omit<HTMLElement, "dataset"> & {
|
type GiscusElement = Omit<HTMLElement, "dataset"> & {
|
||||||
dataset: DOMStringMap & {
|
dataset: DOMStringMap & {
|
||||||
repo: `${string}/${string}`
|
repo: `${string}/${string}`
|
||||||
repoId: string
|
repoId: string
|
||||||
category: string
|
category: string
|
||||||
categoryId: string
|
categoryId: string
|
||||||
|
themeUrl: string
|
||||||
|
lightTheme: string
|
||||||
|
darkTheme: string
|
||||||
mapping: "url" | "title" | "og:title" | "specific" | "number" | "pathname"
|
mapping: "url" | "title" | "og:title" | "specific" | "number" | "pathname"
|
||||||
strict: string
|
strict: string
|
||||||
reactionsEnabled: string
|
reactionsEnabled: string
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user