Skip to content

Quartz-67e1bee #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 32 additions & 46 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"globby": "^14.0.2",
"gray-matter": "^4.0.3",
"hast-util-to-html": "^9.0.3",
"hast-util-to-jsx-runtime": "^2.3.0",
"hast-util-to-jsx-runtime": "^2.3.2",
"hast-util-to-string": "^3.0.1",
"is-absolute-url": "^4.0.1",
"js-yaml": "^4.1.0",
Expand All @@ -59,14 +59,14 @@
"mdast-util-to-hast": "^13.2.0",
"mdast-util-to-string": "^4.0.0",
"micromorph": "^0.4.5",
"pixi.js": "^8.4.1",
"preact": "^10.24.2",
"pixi.js": "^8.5.1",
"preact": "^10.24.3",
"preact-render-to-string": "^6.5.11",
"pretty-bytes": "^6.1.1",
"pretty-time": "^1.1.0",
"reading-time": "^1.5.0",
"rehype-autolink-headings": "^7.1.0",
"rehype-citation": "^2.1.2",
"rehype-citation": "^2.2.0",
"rehype-katex": "^7.0.1",
"rehype-mathjax": "^6.0.0",
"rehype-pretty-code": "^0.14.0",
Expand All @@ -82,15 +82,15 @@
"remark-smartypants": "^3.0.2",
"rfdc": "^1.4.1",
"rimraf": "^6.0.1",
"serve-handler": "^6.1.5",
"serve-handler": "^6.1.6",
"shiki": "^1.22.0",
"source-map-support": "^0.5.21",
"to-vfile": "^8.0.0",
"toml": "^3.0.0",
"unified": "^11.0.5",
"unist-util-visit": "^5.0.0",
"vfile": "^6.0.3",
"workerpool": "^9.1.3",
"workerpool": "^9.2.0",
"ws": "^8.18.0",
"yargs": "^17.7.2"
},
Expand All @@ -99,7 +99,7 @@
"@types/d3": "^7.4.3",
"@types/hast": "^3.0.4",
"@types/js-yaml": "^4.0.9",
"@types/node": "^22.7.5",
"@types/node": "^22.7.7",
"@types/pretty-time": "^1.1.5",
"@types/source-map-support": "^0.5.10",
"@types/ws": "^8.5.12",
Expand Down
8 changes: 8 additions & 0 deletions quartz/components/Comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ type Options = {
repoId: string
category: string
categoryId: string
themeUrl?: string
lightTheme?: string
darkTheme?: string
mapping?: "url" | "title" | "og:title" | "specific" | "number" | "pathname"
strict?: boolean
reactionsEnabled?: boolean
Expand All @@ -34,6 +37,11 @@ export default ((opts: Options) => {
data-strict={boolToStringBool(opts.options.strict ?? true)}
data-reactions-enabled={boolToStringBool(opts.options.reactionsEnabled ?? true)}
data-input-position={opts.options.inputPosition ?? "bottom"}
data-light-theme={opts.options.lightTheme ?? "light"}
data-dark-theme={opts.options.darkTheme ?? "dark"}
data-theme-url={
opts.options.themeUrl ?? `https://${cfg.baseUrl ?? "example.com"}/static/giscus`
}
></div>
)
}
Expand Down
28 changes: 26 additions & 2 deletions quartz/components/scripts/comments.inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,44 @@ const changeTheme = (e: CustomEventMap["themechange"]) => {
{
giscus: {
setConfig: {
theme: theme,
theme: getThemeUrl(getThemeName(theme)),
},
},
},
"https://giscus.app",
)
}

const getThemeName = (theme: string) => {
if (theme !== "dark" && theme !== "light") {
return theme
}
const giscusContainer = document.querySelector(".giscus") as GiscusElement
if (!giscusContainer) {
return theme
}
const darkGiscus = giscusContainer.dataset.darkTheme ?? "dark"
const lightGiscus = giscusContainer.dataset.lightTheme ?? "light"
return theme === "dark" ? darkGiscus : lightGiscus
}

const getThemeUrl = (theme: string) => {
const giscusContainer = document.querySelector(".giscus") as GiscusElement
if (!giscusContainer) {
return `https://giscus.app/themes/${theme}.css`
}
return `${giscusContainer.dataset.themeUrl ?? "https://giscus.app/themes"}/${theme}.css`
}

type GiscusElement = Omit<HTMLElement, "dataset"> & {
dataset: DOMStringMap & {
repo: `${string}/${string}`
repoId: string
category: string
categoryId: string
themeUrl: string
lightTheme: string
darkTheme: string
mapping: "url" | "title" | "og:title" | "specific" | "number" | "pathname"
strict: string
reactionsEnabled: string
Expand Down Expand Up @@ -57,7 +81,7 @@ document.addEventListener("nav", () => {

const theme = document.documentElement.getAttribute("saved-theme")
if (theme) {
giscusScript.setAttribute("data-theme", theme)
giscusScript.setAttribute("data-theme", getThemeUrl(getThemeName(theme)))
}

giscusContainer.appendChild(giscusScript)
Expand Down
2 changes: 1 addition & 1 deletion quartz/components/styles/backlinks.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
display: none;
}
height: auto;
@media all and ($desktop) {
@media all and not ($desktop) {
height: 250px;
}
}
Expand Down
2 changes: 1 addition & 1 deletion quartz/components/styles/graph.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
height: 80vh;
width: 80vw;

@media all and ($desktop) {
@media all and not ($desktop) {
width: 90%;
}
}
Expand Down
2 changes: 1 addition & 1 deletion quartz/components/styles/search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
margin-left: auto;
margin-right: auto;

@media all and ($desktop) {
@media all and not ($desktop) {
width: 90%;
}

Expand Down
3 changes: 2 additions & 1 deletion quartz/plugins/filters/draft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { QuartzFilterPlugin } from "../types"
export const RemoveDrafts: QuartzFilterPlugin<{}> = () => ({
name: "RemoveDrafts",
shouldPublish(_ctx, [_tree, vfile]) {
const draftFlag: boolean = vfile.data?.frontmatter?.draft === true
const draftFlag: boolean =
vfile.data?.frontmatter?.draft === true || vfile.data?.frontmatter?.draft === "true"
return !draftFlag
},
})
2 changes: 1 addition & 1 deletion quartz/plugins/filters/explicit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { QuartzFilterPlugin } from "../types"
export const ExplicitPublish: QuartzFilterPlugin = () => ({
name: "ExplicitPublish",
shouldPublish(_ctx, [_tree, vfile]) {
return vfile.data?.frontmatter?.publish === true
return vfile.data?.frontmatter?.publish === true || vfile.data?.frontmatter?.publish === "true"
},
})
4 changes: 2 additions & 2 deletions quartz/plugins/transformers/frontmatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ declare module "vfile" {
tags: string[]
aliases: string[]
description: string
publish: boolean
draft: boolean
publish: boolean | string
draft: boolean | string
lang: string
enableToc: string
cssclasses: string[]
Expand Down
Loading