Skip to content

Commit b0320cf

Browse files
MasssiveJuice08saberzero1aarnphmdependabot[bot]
authoredJan 27, 2025
Quartz-67e1bee (#109)
* feat(comments): support custom giscus themes (#1526) Co-authored-by: Aaron Pham <Aaronpham0103@gmail.com> Co-authored-by: Aaron Pham <contact@aarnphm.xyz> * fix(grid): $desktop variable (#1511) * Feat(filters): Support "true" as valid for draft and publish frontmatter values (b3a02909ba74fff08cd3675707d1f4d782a24e98) * Merge pull request #1543 from saberzero1/draft-publish-string feat(filters): support "true" as valid for frontmatter filters * chore(deps): bump the production-dependencies group across 1 directory with 7 updates (#1540) --------- Co-authored-by: Emile Bangma <github@emilebangma.com> Co-authored-by: Aaron Pham <Aaronpham0103@gmail.com> Co-authored-by: Aaron Pham <contact@aarnphm.xyz> Co-authored-by: Emile Bangma <ewjbangma@hotmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent ce66337 commit b0320cf

File tree

14 files changed

+285
-67
lines changed

14 files changed

+285
-67
lines changed
 

‎package-lock.json

+32-46
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"globby": "^14.0.2",
5151
"gray-matter": "^4.0.3",
5252
"hast-util-to-html": "^9.0.3",
53-
"hast-util-to-jsx-runtime": "^2.3.0",
53+
"hast-util-to-jsx-runtime": "^2.3.2",
5454
"hast-util-to-string": "^3.0.1",
5555
"is-absolute-url": "^4.0.1",
5656
"js-yaml": "^4.1.0",
@@ -59,14 +59,14 @@
5959
"mdast-util-to-hast": "^13.2.0",
6060
"mdast-util-to-string": "^4.0.0",
6161
"micromorph": "^0.4.5",
62-
"pixi.js": "^8.4.1",
63-
"preact": "^10.24.2",
62+
"pixi.js": "^8.5.1",
63+
"preact": "^10.24.3",
6464
"preact-render-to-string": "^6.5.11",
6565
"pretty-bytes": "^6.1.1",
6666
"pretty-time": "^1.1.0",
6767
"reading-time": "^1.5.0",
6868
"rehype-autolink-headings": "^7.1.0",
69-
"rehype-citation": "^2.1.2",
69+
"rehype-citation": "^2.2.0",
7070
"rehype-katex": "^7.0.1",
7171
"rehype-mathjax": "^6.0.0",
7272
"rehype-pretty-code": "^0.14.0",
@@ -82,15 +82,15 @@
8282
"remark-smartypants": "^3.0.2",
8383
"rfdc": "^1.4.1",
8484
"rimraf": "^6.0.1",
85-
"serve-handler": "^6.1.5",
85+
"serve-handler": "^6.1.6",
8686
"shiki": "^1.22.0",
8787
"source-map-support": "^0.5.21",
8888
"to-vfile": "^8.0.0",
8989
"toml": "^3.0.0",
9090
"unified": "^11.0.5",
9191
"unist-util-visit": "^5.0.0",
9292
"vfile": "^6.0.3",
93-
"workerpool": "^9.1.3",
93+
"workerpool": "^9.2.0",
9494
"ws": "^8.18.0",
9595
"yargs": "^17.7.2"
9696
},
@@ -99,7 +99,7 @@
9999
"@types/d3": "^7.4.3",
100100
"@types/hast": "^3.0.4",
101101
"@types/js-yaml": "^4.0.9",
102-
"@types/node": "^22.7.5",
102+
"@types/node": "^22.7.7",
103103
"@types/pretty-time": "^1.1.5",
104104
"@types/source-map-support": "^0.5.10",
105105
"@types/ws": "^8.5.12",

‎quartz/components/Comments.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ type Options = {
1010
repoId: string
1111
category: string
1212
categoryId: string
13+
themeUrl?: string
14+
lightTheme?: string
15+
darkTheme?: string
1316
mapping?: "url" | "title" | "og:title" | "specific" | "number" | "pathname"
1417
strict?: boolean
1518
reactionsEnabled?: boolean
@@ -34,6 +37,11 @@ export default ((opts: Options) => {
3437
data-strict={boolToStringBool(opts.options.strict ?? true)}
3538
data-reactions-enabled={boolToStringBool(opts.options.reactionsEnabled ?? true)}
3639
data-input-position={opts.options.inputPosition ?? "bottom"}
40+
data-light-theme={opts.options.lightTheme ?? "light"}
41+
data-dark-theme={opts.options.darkTheme ?? "dark"}
42+
data-theme-url={
43+
opts.options.themeUrl ?? `https://${cfg.baseUrl ?? "example.com"}/static/giscus`
44+
}
3745
></div>
3846
)
3947
}

‎quartz/components/scripts/comments.inline.ts

+26-2
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,44 @@ const changeTheme = (e: CustomEventMap["themechange"]) => {
1313
{
1414
giscus: {
1515
setConfig: {
16-
theme: theme,
16+
theme: getThemeUrl(getThemeName(theme)),
1717
},
1818
},
1919
},
2020
"https://giscus.app",
2121
)
2222
}
2323

24+
const getThemeName = (theme: string) => {
25+
if (theme !== "dark" && theme !== "light") {
26+
return theme
27+
}
28+
const giscusContainer = document.querySelector(".giscus") as GiscusElement
29+
if (!giscusContainer) {
30+
return theme
31+
}
32+
const darkGiscus = giscusContainer.dataset.darkTheme ?? "dark"
33+
const lightGiscus = giscusContainer.dataset.lightTheme ?? "light"
34+
return theme === "dark" ? darkGiscus : lightGiscus
35+
}
36+
37+
const getThemeUrl = (theme: string) => {
38+
const giscusContainer = document.querySelector(".giscus") as GiscusElement
39+
if (!giscusContainer) {
40+
return `https://giscus.app/themes/${theme}.css`
41+
}
42+
return `${giscusContainer.dataset.themeUrl ?? "https://giscus.app/themes"}/${theme}.css`
43+
}
44+
2445
type GiscusElement = Omit<HTMLElement, "dataset"> & {
2546
dataset: DOMStringMap & {
2647
repo: `${string}/${string}`
2748
repoId: string
2849
category: string
2950
categoryId: string
51+
themeUrl: string
52+
lightTheme: string
53+
darkTheme: string
3054
mapping: "url" | "title" | "og:title" | "specific" | "number" | "pathname"
3155
strict: string
3256
reactionsEnabled: string
@@ -57,7 +81,7 @@ document.addEventListener("nav", () => {
5781

5882
const theme = document.documentElement.getAttribute("saved-theme")
5983
if (theme) {
60-
giscusScript.setAttribute("data-theme", theme)
84+
giscusScript.setAttribute("data-theme", getThemeUrl(getThemeName(theme)))
6185
}
6286

6387
giscusContainer.appendChild(giscusScript)

‎quartz/components/styles/backlinks.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
display: none;
3838
}
3939
height: auto;
40-
@media all and ($desktop) {
40+
@media all and not ($desktop) {
4141
height: 250px;
4242
}
4343
}

‎quartz/components/styles/graph.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
height: 80vh;
6666
width: 80vw;
6767

68-
@media all and ($desktop) {
68+
@media all and not ($desktop) {
6969
width: 90%;
7070
}
7171
}

‎quartz/components/styles/search.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
margin-left: auto;
6565
margin-right: auto;
6666

67-
@media all and ($desktop) {
67+
@media all and not ($desktop) {
6868
width: 90%;
6969
}
7070

‎quartz/plugins/filters/draft.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { QuartzFilterPlugin } from "../types"
33
export const RemoveDrafts: QuartzFilterPlugin<{}> = () => ({
44
name: "RemoveDrafts",
55
shouldPublish(_ctx, [_tree, vfile]) {
6-
const draftFlag: boolean = vfile.data?.frontmatter?.draft === true
6+
const draftFlag: boolean =
7+
vfile.data?.frontmatter?.draft === true || vfile.data?.frontmatter?.draft === "true"
78
return !draftFlag
89
},
910
})

‎quartz/plugins/filters/explicit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { QuartzFilterPlugin } from "../types"
33
export const ExplicitPublish: QuartzFilterPlugin = () => ({
44
name: "ExplicitPublish",
55
shouldPublish(_ctx, [_tree, vfile]) {
6-
return vfile.data?.frontmatter?.publish === true
6+
return vfile.data?.frontmatter?.publish === true || vfile.data?.frontmatter?.publish === "true"
77
},
88
})

‎quartz/plugins/transformers/frontmatter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ declare module "vfile" {
8888
tags: string[]
8989
aliases: string[]
9090
description: string
91-
publish: boolean
92-
draft: boolean
91+
publish: boolean | string
92+
draft: boolean | string
9393
lang: string
9494
enableToc: string
9595
cssclasses: string[]

0 commit comments

Comments
 (0)