Skip to content

Commit 759bff5

Browse files
committed
Add Kitchensink, important hydration fix
1 parent fb28283 commit 759bff5

File tree

8 files changed

+227
-29
lines changed

8 files changed

+227
-29
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@types/color": "^3.0.5",
2323
"@types/express": "^4",
2424
"@types/node": "^20.8.9",
25+
"@types/prismjs": "^1",
2526
"@types/react": "^18",
2627
"@types/react-dom": "^18",
2728
"@types/react-helmet-async": "^1.0.3",
@@ -57,6 +58,7 @@
5758
"github-slugger": "^2.0.0",
5859
"hast-util-to-text": "^4.0.0",
5960
"prism-react-renderer": "^2.1.0",
61+
"prismjs": "^1.29.0",
6062
"react": "^18.2.0",
6163
"react-dom": "^18.2.0",
6264
"react-helmet-async": "^1.3.0",

project-words.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@ huayu
88
infty
99
joshcena
1010
katex
11+
kitchensink
12+
kwargs
1113
luo
1214
mathcal
1315
mdast
1416
mdxjs
1517
metastring
1618
noninteractive
1719
noreply
20+
numpy
1821
peaceiris
1922
pipeable
2023
posix
24+
randcolor
2125
rehype
2226
saturationl
2327
scrolly
@@ -27,4 +31,5 @@ svgr
2731
triaging
2832
tseslint
2933
wfla
34+
wordcloud
3035
zhihu

server/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ export async function createServer(
4444
)) as typeof import("../src/server-entry");
4545

4646
const context: Record<string, unknown> = {};
47-
const appHtml = await render(url, context);
47+
const appHTML = await render(url, context);
4848

4949
const html = template
50-
.replace("<!--body-->", appHtml.body)
51-
.replace("<!--metaTags-->", appHtml.metaTags)
52-
.replace(/(?<=<head[^>]+)(?=>)/, ` ${appHtml.htmlAttributes}`)
53-
.replace(/(?<=<body[^>]+)(?=>)/, ` ${appHtml.bodyAttributes}`);
50+
// The HTML may contain dollar signs, which should not be special!
51+
.replace("<!--body-->", () => appHTML.body)
52+
.replace("<!--metaTags-->", () => appHTML.metaTags)
53+
.replace(/(?<=<head[^>]+)(?=>)/, () => ` ${appHTML.htmlAttributes}`)
54+
.replace(/(?<=<body[^>]+)(?=>)/, () => ` ${appHTML.bodyAttributes}`);
5455

5556
res
5657
.status(Number(context.status ?? 200))
@@ -63,7 +64,7 @@ export async function createServer(
6364
throw e;
6465
}
6566
viteServer.ssrFixStacktrace(e);
66-
console.log(e.stack);
67+
console.log(e);
6768
res.status(500).end(e.stack);
6869
}
6970
});

src/components/CodeBlock/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default function CodeBlock({
7171
<span
7272
// eslint-disable-next-line react/no-array-index-key
7373
key={j}
74-
{...getTokenProps({ token, key: j })}
74+
{...getTokenProps({ token })}
7575
/>
7676
))}
7777
<br />

src/global.css

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,6 @@
4646
--color-shadow: #ffffff20;
4747
}
4848

49-
code {
50-
font-family: var(--font-code);
51-
font-size: small;
52-
background-color: var(--color-shadow);
53-
padding: 4px;
54-
border-radius: 4px;
55-
color: var(--color-text);
56-
}
57-
58-
pre {
59-
font-family: var(--font-code);
60-
font-size: 1em;
61-
}
62-
63-
pre code {
64-
background-color: transparent;
65-
padding: 0;
66-
border-radius: 0;
67-
color: unset;
68-
}
69-
7049
@font-face {
7150
font-family: CharisSILW;
7251
src: url(assets/CharisSIL-Regular.woff2);
@@ -130,6 +109,38 @@ button {
130109
font-size: 1em;
131110
}
132111

112+
code {
113+
font-family: var(--font-code);
114+
font-size: small;
115+
background-color: var(--color-shadow);
116+
padding: 4px;
117+
border-radius: 4px;
118+
color: var(--color-text);
119+
}
120+
121+
pre {
122+
font-family: var(--font-code);
123+
font-size: 1em;
124+
}
125+
126+
pre code {
127+
background-color: transparent;
128+
padding: 0;
129+
border-radius: 0;
130+
color: unset;
131+
}
132+
133+
blockquote {
134+
padding-left: 1em;
135+
border-left: 4px solid var(--color-text-subdued);
136+
color: var(--color-text-subdued);
137+
margin-block-start: 0;
138+
margin-block-end: 0;
139+
margin-inline-start: 0;
140+
margin-inline-end: 0;
141+
margin-left: var(--margin-paragraph);
142+
}
143+
133144
.tooltip {
134145
--rt-opacity: 1;
135146
background-color: var(--color-background);

src/pages/index.module.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
display: flex;
33
flex-direction: row;
44
justify-content: center;
5+
border: none;
6+
color: var(--color-text);
7+
margin: 0;
8+
margin-top: 2em;
9+
padding: 0;
510
}
611

712
.quote::before,

src/pages/notes/kitchensink.mdx

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
---
2+
description: A collection of all Markdown syntaxes — for testing
3+
---
4+
5+
# Kitchensink
6+
7+
import text from "./kitchensink.mdx?raw";
8+
import CodeBlock from "@/components/CodeBlock";
9+
10+
<details>
11+
<summary>Markdown source</summary>
12+
<CodeBlock language="md">{text}</CodeBlock>
13+
</details>
14+
15+
## Basic Markdown
16+
17+
### H3
18+
19+
#### H4
20+
21+
##### H5
22+
23+
###### H6
24+
25+
- _Italic_
26+
- **Bold**
27+
- **_Bold and italic_**
28+
- ~~Strikethrough~~
29+
- `Inline code`
30+
- [Link](https://www.example.com)
31+
- [Link with title](https://www.example.com "Example")
32+
33+
A normal paragraph:
34+
35+
> Blockquote
36+
>
37+
> > Nested blockquote
38+
>
39+
> Yes
40+
41+
Another normal paragraph:
42+
43+
1. `ol`
44+
- `ol > ul`
45+
- `ol > ul > ul`
46+
- ...
47+
- ...
48+
2. ...
49+
1. `ol > ol`
50+
2. ...
51+
52+
- [x] Task list
53+
- [ ] Task
54+
- [ ] Task
55+
- [ ] Nested
56+
- [ ] Nested
57+
58+
![Local image](assets/yale-logo.png)
59+
60+
This is a rule:
61+
62+
---
63+
64+
Footnote[^1]
65+
66+
Named footnote[^named]
67+
68+
[^named]: This is a named footnote.
69+
[^1]: This is a footnote.
70+
71+
## Math
72+
73+
Inline: $x^2 + y^2 = z^2$
74+
75+
Block:
76+
77+
$$
78+
\begin{aligned}
79+
x^2 + y^2 &= z^2 \\
80+
x^2 &= z^2 - y^2 \\
81+
x &= \sqrt{z^2 - y^2}
82+
\end{aligned}
83+
$$
84+
85+
## Code snippets
86+
87+
```plain
88+
___________________________
89+
< I'm an expert in my field. >
90+
---------------------------
91+
\ ^__^
92+
\ (oo)\_______
93+
(__)\ )\/\
94+
||----w |
95+
|| ||
96+
```
97+
98+
```html
99+
<pre></pre>
100+
```
101+
102+
```js
103+
const f = () => {
104+
return Math.random();
105+
};
106+
```
107+
108+
```css
109+
:root {
110+
--first-color: #488cff;
111+
--second-color: #ffff8c;
112+
}
113+
114+
#firstParagraph {
115+
background-color: var(--first-color);
116+
color: var(--second-color);
117+
}
118+
```
119+
120+
```rust
121+
#[cfg(test)]
122+
mod tests {
123+
#[test]
124+
fn it_works() {
125+
assert_eq!(2 + 2, 4);
126+
}
127+
}
128+
```
129+
130+
```python
131+
from wordcloud import WordCloud
132+
import pandas as pd
133+
import numpy as np
134+
135+
color1 = np.array([69, 61, 59])
136+
color2 = np.array([38, 90, 77])
137+
138+
name = 'song'
139+
df = pd.read_csv(f'{name}_count.csv', names=['name', 'count'])
140+
freq = dict(zip(df['name'], df['count']))
141+
142+
def color_func(word, font_size, position, orientation, random_state=None, **kwargs):
143+
randcolor = color1 + np.floor((color2 - color1) * np.random.random())
144+
return("rgb(%d, %d, %d)" % tuple(randcolor))
145+
```
146+
147+
## Tables
148+
149+
### Markdown table
150+
151+
| Tables | Are | Cool |
152+
| ------------- | :-----------: | -----: |
153+
| col 3 is | right-aligned | \$1600 |
154+
| col 2 is | centered | \$12 |
155+
| zebra stripes | are neat | \$1 |
156+
157+
## HTML
158+
159+
<dl>
160+
<dt>Definition list</dt>
161+
<dd>Is something people use sometimes.</dd>
162+
163+
<dt>Markdown in HTML</dt>
164+
<dd>_Works_! **HTML** <em>works</em> too.</dd>
165+
</dl>

yarn.lock

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ __metadata:
15981598
languageName: node
15991599
linkType: hard
16001600

1601-
"@types/prismjs@npm:^1.26.0":
1601+
"@types/prismjs@npm:^1, @types/prismjs@npm:^1.26.0":
16021602
version: 1.26.3
16031603
resolution: "@types/prismjs@npm:1.26.3"
16041604
checksum: 3e8a64bcf0ab5f9a47ec2590938c5a8a20ac849b4949a95ed96e73e64cb890fc56e9c9b724286914717458267b28405f965709e1b9f80db5d68817a7ce5a18a9
@@ -7038,6 +7038,7 @@ __metadata:
70387038
"@types/color": "npm:^3.0.5"
70397039
"@types/express": "npm:^4"
70407040
"@types/node": "npm:^20.8.9"
7041+
"@types/prismjs": "npm:^1"
70417042
"@types/react": "npm:^18"
70427043
"@types/react-dom": "npm:^18"
70437044
"@types/react-helmet-async": "npm:^1.0.3"
@@ -7065,6 +7066,7 @@ __metadata:
70657066
prettier: "npm:^3.0.3"
70667067
prettier-config-jc: "npm:^2.3.0"
70677068
prism-react-renderer: "npm:^2.1.0"
7069+
prismjs: "npm:^1.29.0"
70687070
react: "npm:^18.2.0"
70697071
react-dom: "npm:^18.2.0"
70707072
react-helmet-async: "npm:^1.3.0"
@@ -7228,6 +7230,13 @@ __metadata:
72287230
languageName: node
72297231
linkType: hard
72307232

7233+
"prismjs@npm:^1.29.0":
7234+
version: 1.29.0
7235+
resolution: "prismjs@npm:1.29.0"
7236+
checksum: d906c4c4d01b446db549b4f57f72d5d7e6ccaca04ecc670fb85cea4d4b1acc1283e945a9cbc3d81819084a699b382f970e02f9d1378e14af9808d366d9ed7ec6
7237+
languageName: node
7238+
linkType: hard
7239+
72317240
"promise-retry@npm:^2.0.1":
72327241
version: 2.0.1
72337242
resolution: "promise-retry@npm:2.0.1"

0 commit comments

Comments
 (0)