Skip to content

Commit de446b8

Browse files
committed
Quartz sync: May 21, 2025, 10:24 PM
1 parent 6901e39 commit de446b8

File tree

14 files changed

+781
-37
lines changed

14 files changed

+781
-37
lines changed

content/Computer Science/1 Foundations & Theory/Algorithms/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description:
33
created: 2023-10-09
4-
modified: 2025-05-18
4+
modified: 2025-05-21
55
tags:
66
- cs
77
- algorithm

content/Computer Science/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ aliases:
1313

1414
- Foundations & Theory
1515
- Data Structures
16-
- [[- Algorithms | 🗺️ - Algorithms]]
16+
- [[- Algorithms| 🗺️ - Algorithms]]
1717
- Theory of Computation
1818
- Discrete Mathematics
1919
- Probability & Statistics

content/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ comments: "false"
1414
# MOC
1515
- [[About|About]]
1616
- [[- Computer Science | 🗺️ - Computer Science]]
17-
- [[- Algorithms | 🗺️ - Algorithms]]
17+
- [[- Algorithms| 🗺️ - Algorithms]]
1818
- [[- PS |🗺️ - PS]]
1919
- [[- Frontend| 🗺️ - Frontend]]
2020
- [[- Note Taking|🗺️ - Note Taking]]

package-lock.json

Lines changed: 442 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
"is-absolute-url": "^4.0.1",
6060
"js-yaml": "^4.1.0",
6161
"lightningcss": "^1.30.1",
62+
"markmap-common": "^0.18.9",
63+
"markmap-lib": "^0.18.11",
64+
"markmap-toolbar": "^0.18.10",
65+
"markmap-view": "^0.18.10",
6266
"mdast-util-find-and-replace": "^3.0.2",
6367
"mdast-util-to-hast": "^13.2.0",
6468
"mdast-util-to-string": "^4.0.0",

quartz.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const config: QuartzConfig = {
8080
Plugin.CrawlLinks({ markdownLinkResolution: "shortest" }),
8181
Plugin.Description(),
8282
Plugin.Latex({ renderEngine: "katex" }),
83+
Plugin.MarkmapTransformer(),
8384
],
8485
filters: [
8586
Plugin.RemoveDrafts(),

quartz.layout.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export const defaultContentPageLayout: PageLayout = {
5454
grow: true,
5555
},
5656
{ Component: Component.Darkmode() },
57+
{ Component: Component.MarkmapViewer() },
5758
{ Component: Component.DesktopOnly(Component.ReaderMode()) },
5859
],
5960
}),
@@ -112,6 +113,7 @@ export const defaultListPageLayout: PageLayout = {
112113
grow: true,
113114
},
114115
{ Component: Component.Darkmode() },
116+
{ Component: Component.MarkmapViewer() },
115117
{ Component: Component.DesktopOnly(Component.ReaderMode()) },
116118
],
117119
}),

quartz/components/Darkmode.tsx

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,40 @@ import { i18n } from "../i18n"
66
import { classNames } from "../util/lang"
77

88
const Darkmode: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => {
9-
return (
10-
<button class={classNames(displayClass, "darkmode")}>
11-
<svg
12-
xmlns="http://www.w3.org/2000/svg"
13-
xmlnsXlink="http://www.w3.org/1999/xlink"
14-
version="1.1"
15-
class="dayIcon"
16-
x="0px"
17-
y="0px"
18-
viewBox="0 0 35 35"
19-
style="enable-background:new 0 0 35 35"
20-
xmlSpace="preserve"
21-
aria-label={i18n(cfg.locale).components.themeToggle.darkMode}
22-
>
23-
<title>{i18n(cfg.locale).components.themeToggle.darkMode}</title>
24-
<path d="M6,17.5C6,16.672,5.328,16,4.5,16h-3C0.672,16,0,16.672,0,17.5 S0.672,19,1.5,19h3C5.328,19,6,18.328,6,17.5z M7.5,26c-0.414,0-0.789,0.168-1.061,0.439l-2,2C4.168,28.711,4,29.086,4,29.5 C4,30.328,4.671,31,5.5,31c0.414,0,0.789-0.168,1.06-0.44l2-2C8.832,28.289,9,27.914,9,27.5C9,26.672,8.329,26,7.5,26z M17.5,6 C18.329,6,19,5.328,19,4.5v-3C19,0.672,18.329,0,17.5,0S16,0.672,16,1.5v3C16,5.328,16.671,6,17.5,6z M27.5,9 c0.414,0,0.789-0.168,1.06-0.439l2-2C30.832,6.289,31,5.914,31,5.5C31,4.672,30.329,4,29.5,4c-0.414,0-0.789,0.168-1.061,0.44 l-2,2C26.168,6.711,26,7.086,26,7.5C26,8.328,26.671,9,27.5,9z M6.439,8.561C6.711,8.832,7.086,9,7.5,9C8.328,9,9,8.328,9,7.5 c0-0.414-0.168-0.789-0.439-1.061l-2-2C6.289,4.168,5.914,4,5.5,4C4.672,4,4,4.672,4,5.5c0,0.414,0.168,0.789,0.439,1.06 L6.439,8.561z M33.5,16h-3c-0.828,0-1.5,0.672-1.5,1.5s0.672,1.5,1.5,1.5h3c0.828,0,1.5-0.672,1.5-1.5S34.328,16,33.5,16z M28.561,26.439C28.289,26.168,27.914,26,27.5,26c-0.828,0-1.5,0.672-1.5,1.5c0,0.414,0.168,0.789,0.439,1.06l2,2 C28.711,30.832,29.086,31,29.5,31c0.828,0,1.5-0.672,1.5-1.5c0-0.414-0.168-0.789-0.439-1.061L28.561,26.439z M17.5,29 c-0.829,0-1.5,0.672-1.5,1.5v3c0,0.828,0.671,1.5,1.5,1.5s1.5-0.672,1.5-1.5v-3C19,29.672,18.329,29,17.5,29z M17.5,7 C11.71,7,7,11.71,7,17.5S11.71,28,17.5,28S28,23.29,28,17.5S23.29,7,17.5,7z M17.5,25c-4.136,0-7.5-3.364-7.5-7.5 c0-4.136,3.364-7.5,7.5-7.5c4.136,0,7.5,3.364,7.5,7.5C25,21.636,21.636,25,17.5,25z"></path>
25-
</svg>
26-
<svg
27-
xmlns="http://www.w3.org/2000/svg"
28-
xmlnsXlink="http://www.w3.org/1999/xlink"
29-
version="1.1"
30-
class="nightIcon"
31-
x="0px"
32-
y="0px"
33-
viewBox="0 0 100 100"
34-
style="enable-background:new 0 0 100 100"
35-
xmlSpace="preserve"
36-
aria-label={i18n(cfg.locale).components.themeToggle.lightMode}
37-
>
38-
<title>{i18n(cfg.locale).components.themeToggle.lightMode}</title>
39-
<path d="M96.76,66.458c-0.853-0.852-2.15-1.064-3.23-0.534c-6.063,2.991-12.858,4.571-19.655,4.571 C62.022,70.495,50.88,65.88,42.5,57.5C29.043,44.043,25.658,23.536,34.076,6.47c0.532-1.08,0.318-2.379-0.534-3.23 c-0.851-0.852-2.15-1.064-3.23-0.534c-4.918,2.427-9.375,5.619-13.246,9.491c-9.447,9.447-14.65,22.008-14.65,35.369 c0,13.36,5.203,25.921,14.65,35.368s22.008,14.65,35.368,14.65c13.361,0,25.921-5.203,35.369-14.65 c3.872-3.871,7.064-8.328,9.491-13.246C97.826,68.608,97.611,67.309,96.76,66.458z"></path>
40-
</svg>
41-
</button>
42-
)
9+
return (
10+
<button class={classNames(displayClass, "darkmode")}>
11+
<svg
12+
xmlns="http://www.w3.org/2000/svg"
13+
xmlnsXlink="http://www.w3.org/1999/xlink"
14+
version="1.1"
15+
class="dayIcon"
16+
x="0px"
17+
y="0px"
18+
viewBox="0 0 35 35"
19+
style="enable-background:new 0 0 35 35"
20+
xmlSpace="preserve"
21+
aria-label={i18n(cfg.locale).components.themeToggle.darkMode}
22+
>
23+
<title>{i18n(cfg.locale).components.themeToggle.darkMode}</title>
24+
<path d="M6,17.5C6,16.672,5.328,16,4.5,16h-3C0.672,16,0,16.672,0,17.5 S0.672,19,1.5,19h3C5.328,19,6,18.328,6,17.5z M7.5,26c-0.414,0-0.789,0.168-1.061,0.439l-2,2C4.168,28.711,4,29.086,4,29.5 C4,30.328,4.671,31,5.5,31c0.414,0,0.789-0.168,1.06-0.44l2-2C8.832,28.289,9,27.914,9,27.5C9,26.672,8.329,26,7.5,26z M17.5,6 C18.329,6,19,5.328,19,4.5v-3C19,0.672,18.329,0,17.5,0S16,0.672,16,1.5v3C16,5.328,16.671,6,17.5,6z M27.5,9 c0.414,0,0.789-0.168,1.06-0.439l2-2C30.832,6.289,31,5.914,31,5.5C31,4.672,30.329,4,29.5,4c-0.414,0-0.789,0.168-1.061,0.44 l-2,2C26.168,6.711,26,7.086,26,7.5C26,8.328,26.671,9,27.5,9z M6.439,8.561C6.711,8.832,7.086,9,7.5,9C8.328,9,9,8.328,9,7.5 c0-0.414-0.168-0.789-0.439-1.061l-2-2C6.289,4.168,5.914,4,5.5,4C4.672,4,4,4.672,4,5.5c0,0.414,0.168,0.789,0.439,1.06 L6.439,8.561z M33.5,16h-3c-0.828,0-1.5,0.672-1.5,1.5s0.672,1.5,1.5,1.5h3c0.828,0,1.5-0.672,1.5-1.5S34.328,16,33.5,16z M28.561,26.439C28.289,26.168,27.914,26,27.5,26c-0.828,0-1.5,0.672-1.5,1.5c0,0.414,0.168,0.789,0.439,1.06l2,2 C28.711,30.832,29.086,31,29.5,31c0.828,0,1.5-0.672,1.5-1.5c0-0.414-0.168-0.789-0.439-1.061L28.561,26.439z M17.5,29 c-0.829,0-1.5,0.672-1.5,1.5v3c0,0.828,0.671,1.5,1.5,1.5s1.5-0.672,1.5-1.5v-3C19,29.672,18.329,29,17.5,29z M17.5,7 C11.71,7,7,11.71,7,17.5S11.71,28,17.5,28S28,23.29,28,17.5S23.29,7,17.5,7z M17.5,25c-4.136,0-7.5-3.364-7.5-7.5 c0-4.136,3.364-7.5,7.5-7.5c4.136,0,7.5,3.364,7.5,7.5C25,21.636,21.636,25,17.5,25z"></path>
25+
</svg>
26+
<svg
27+
xmlns="http://www.w3.org/2000/svg"
28+
xmlnsXlink="http://www.w3.org/1999/xlink"
29+
version="1.1"
30+
class="nightIcon"
31+
x="0px"
32+
y="0px"
33+
viewBox="0 0 100 100"
34+
style="enable-background:new 0 0 100 100"
35+
xmlSpace="preserve"
36+
aria-label={i18n(cfg.locale).components.themeToggle.lightMode}
37+
>
38+
<title>{i18n(cfg.locale).components.themeToggle.lightMode}</title>
39+
<path d="M96.76,66.458c-0.853-0.852-2.15-1.064-3.23-0.534c-6.063,2.991-12.858,4.571-19.655,4.571 C62.022,70.495,50.88,65.88,42.5,57.5C29.043,44.043,25.658,23.536,34.076,6.47c0.532-1.08,0.318-2.379-0.534-3.23 c-0.851-0.852-2.15-1.064-3.23-0.534c-4.918,2.427-9.375,5.619-13.246,9.491c-9.447,9.447-14.65,22.008-14.65,35.369 c0,13.36,5.203,25.921,14.65,35.368s22.008,14.65,35.368,14.65c13.361,0,25.921-5.203,35.369-14.65 c3.872-3.871,7.064-8.328,9.491-13.246C97.826,68.608,97.611,67.309,96.76,66.458z"></path>
40+
</svg>
41+
</button>
42+
)
4343
}
4444

4545
Darkmode.beforeDOMLoaded = darkmodeScript
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// @ts-ignore
2+
import markmapScript from "./scripts/markmap.inline"
3+
import style from "./styles/markmap.scss"
4+
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
5+
import { classNames } from "../util/lang"
6+
7+
import { IPureNode } from 'markmap-common'
8+
9+
10+
const recurseChildren = (fn: (node: IPureNode) => void) => (node: IPureNode) => {
11+
fn(node)
12+
node.children?.forEach(recurseChildren(fn))
13+
}
14+
15+
function* matchRegex(str: string, regex: RegExp) {
16+
while (true) {
17+
const match = regex.exec(str)
18+
if (!match) break
19+
yield match
20+
}
21+
}
22+
23+
function replaceMatches(str: string, regex: RegExp, replacer: (match: RegExpExecArray) => string) {
24+
let accumulator = str
25+
const matches = matchRegex(str, regex)
26+
for (const match of matches)
27+
accumulator = accumulator.replace(match[0], replacer(match))
28+
return accumulator
29+
}
30+
31+
32+
const wikilinkRegex = /\[\[(?<link>[^|\]]+)\|?((?<displayText>[^\]]+))?\]\]/g
33+
34+
function replacement(match) {
35+
const { link, displayText } = match.groups!
36+
const safeLink = link.trim().replace(/\s+/g, "-")
37+
// return `<a href=\"/${safeLink}\">${displayText || link}</a>`
38+
return `"${displayText || link}"`
39+
}
40+
41+
export const parseInternalLinks = recurseChildren(node => {
42+
node.content =
43+
replaceMatches(node.content, wikilinkRegex, replacement)
44+
})
45+
46+
47+
const MarkmapViewer: QuartzComponent = ({ displayClass, fileData }: QuartzComponentProps) => {
48+
const root = fileData.markmap
49+
if (!root) {
50+
return (
51+
<div class={classNames(displayClass, "markmap")}>
52+
<button class={classNames(displayClass, "markmapmode")}>
53+
<svg
54+
xmlns="http://www.w3.org/2000/svg"
55+
class="markmapIcon"
56+
fill="currentColor"
57+
stroke="currentColor"
58+
stroke-width="0.2"
59+
stroke-linecap="round"
60+
stroke-linejoin="round"
61+
width="64px"
62+
height="64px"
63+
viewBox="0 -960 960 960"
64+
aria-label="mind map"
65+
>
66+
<title>mind map</title>
67+
<path d="M200-80q-50 0-85-35t-35-85q0-39 22.5-70t57.5-43v-87q0-50 35-85t85-35h160v-127q-35-12-57.5-43T360-760q0-50 35-85t85-35q50 0 85 35t35 85q0 39-22.5 70T520-647v127h160q50 0 85 35t35 85v87q35 12 57.5 43t22.5 70q0 50-35 85t-85 35q-50 0-85-35t-35-85q0-39 22.5-70t57.5-43v-87q0-17-11.5-28.5T680-440H520v127q35 12 57.5 43t22.5 70q0 50-35 85t-85 35q-50 0-85-35t-35-85q0-39 22.5-70t57.5-43v-127H280q-17 0-28.5 11.5T240-400v87q35 12 57.5 43t22.5 70q0 50-35 85t-85 35Zm0-80q17 0 28.5-11.5T240-200q0-17-11.5-28.5T200-240q-17 0-28.5 11.5T160-200q0 17 11.5 28.5T200-160Zm280 0q17 0 28.5-11.5T520-200q0-17-11.5-28.5T480-240q-17 0-28.5 11.5T440-200q0 17 11.5 28.5T480-160Zm280 0q17 0 28.5-11.5T800-200q0-17-11.5-28.5T760-240q-17 0-28.5 11.5T720-200q0 17 11.5 28.5T760-160ZM480-720q17 0 28.5-11.5T520-760q0-17-11.5-28.5T480-800q-17 0-28.5 11.5T440-760q0 17 11.5 28.5T480-720Z" />
68+
</svg>
69+
</button>
70+
</div>
71+
)
72+
}
73+
74+
parseInternalLinks(root)
75+
76+
return (
77+
<div class={classNames(displayClass, "markmap")}>
78+
79+
<button id="show-markmap" class={classNames(displayClass, "markmapmode")}>
80+
<svg
81+
xmlns="http://www.w3.org/2000/svg"
82+
class="markmapIcon"
83+
fill="currentColor"
84+
stroke="currentColor"
85+
stroke-width="0.2"
86+
stroke-linecap="round"
87+
stroke-linejoin="round"
88+
width="64px"
89+
height="64px"
90+
viewBox="0 -960 960 960"
91+
aria-label="mind map"
92+
>
93+
<title>mind map</title>
94+
<path d="M200-80q-50 0-85-35t-35-85q0-39 22.5-70t57.5-43v-87q0-50 35-85t85-35h160v-127q-35-12-57.5-43T360-760q0-50 35-85t85-35q50 0 85 35t35 85q0 39-22.5 70T520-647v127h160q50 0 85 35t35 85v87q35 12 57.5 43t22.5 70q0 50-35 85t-85 35q-50 0-85-35t-35-85q0-39 22.5-70t57.5-43v-87q0-17-11.5-28.5T680-440H520v127q35 12 57.5 43t22.5 70q0 50-35 85t-85 35q-50 0-85-35t-35-85q0-39 22.5-70t57.5-43v-127H280q-17 0-28.5 11.5T240-400v87q35 12 57.5 43t22.5 70q0 50-35 85t-85 35Zm0-80q17 0 28.5-11.5T240-200q0-17-11.5-28.5T200-240q-17 0-28.5 11.5T160-200q0 17 11.5 28.5T200-160Zm280 0q17 0 28.5-11.5T520-200q0-17-11.5-28.5T480-240q-17 0-28.5 11.5T440-200q0 17 11.5 28.5T480-160Zm280 0q17 0 28.5-11.5T800-200q0-17-11.5-28.5T760-240q-17 0-28.5 11.5T720-200q0 17 11.5 28.5T760-160ZM480-720q17 0 28.5-11.5T520-760q0-17-11.5-28.5T480-800q-17 0-28.5 11.5T440-760q0 17 11.5 28.5T480-720Z" />
95+
</svg>
96+
</button>
97+
<div class="global-markmap-outer">
98+
<div class="global-markmap-container">
99+
<svg id="global-markmap" ></svg>
100+
<div id="global-markmap-toolbar"></div>
101+
<script
102+
id="global-markmap-data"
103+
type="application/json"
104+
dangerouslySetInnerHTML={{ __html: JSON.stringify(fileData.markmap) }}
105+
/>
106+
</div>
107+
</div>
108+
</div>
109+
)
110+
}
111+
112+
MarkmapViewer.afterDOMLoaded = markmapScript
113+
MarkmapViewer.css = style
114+
115+
export default (() => MarkmapViewer) satisfies QuartzComponentConstructor

quartz/components/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Comments from "./Comments"
2424
import Flex from "./Flex"
2525
import ConditionalRender from "./ConditionalRender"
2626
import ScrollProgress from "./ScrollProgress"
27+
import MarkmapViewer from './MarkmapViewer'
2728

2829
export {
2930
ArticleTitle,
@@ -52,4 +53,5 @@ export {
5253
Flex,
5354
ConditionalRender,
5455
ScrollProgress,
56+
MarkmapViewer,
5557
}

0 commit comments

Comments
 (0)