Skip to content

Commit 3e83cb0

Browse files
authored
Refresh workshop reader typography (#4176)
1 parent bce08a2 commit 3e83cb0

2 files changed

Lines changed: 52 additions & 6 deletions

File tree

‎scripts/build-docs.test.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ test("workshop SPA renders a single document h1", () => {
5151
assert.ok((html.match(/<h2 id="[^"]+" class="workshop-page-title">/g) ?? []).length > 0);
5252
});
5353

54+
test("workshop typography uses the bundled Mona Sans and fluid reading scale", () => {
55+
const { html, css } = buildDocs();
56+
57+
assert.ok(html.includes('<link rel="stylesheet" href="mona-sans.css">'));
58+
assert.ok(fs.existsSync(path.join(repoDir, "dist", "fonts", "mona-sans-latin-wght-normal.woff2")));
59+
assert.match(css, /--workshop-type-body: clamp\(/);
60+
assert.match(css, /--workshop-type-title: clamp\(/);
61+
assert.match(css, /\.markdown-body p,\s*\.markdown-body li \{[\s\S]*?line-height: 1\.7;/);
62+
assert.match(css, /\.markdown-body > details > \.workshop-page-title \{[\s\S]*?font-weight: 400;/);
63+
assert.match(css, /\.markdown-body h2:not\(\.workshop-page-title\) \{[\s\S]*?font-weight: 400;/);
64+
assert.match(css, /\.markdown-body h3 \{[\s\S]*?font-weight: 600;/);
65+
});
66+
5467
test("workshop navigation constrains long buttons on small screens", () => {
5568
const { css } = buildDocs();
5669

‎scripts/lib/docs.css‎

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
--workshop-link-color: var(--fgColor-accent, #0969da);
55
--workshop-link-visited-color: var(--fgColor-done, #8250df);
66
--workshop-link-hover-color: var(--fgColor-accent, #0550ae);
7+
--workshop-type-body: clamp(1rem, 0.955rem + 0.227vw, 1.125rem);
8+
--workshop-type-title: clamp(2.25rem, 1.977rem + 1.364vw, 3rem);
9+
--workshop-type-section: clamp(1.75rem, 1.477rem + 1.364vw, 2.5rem);
10+
--workshop-type-subheading: clamp(1.375rem, 1.239rem + 0.682vw, 1.75rem);
711
}
812

913
@media (prefers-color-scheme: dark) {
@@ -23,6 +27,8 @@ html[data-color-mode="dark"] {
2327
body,
2428
.markdown-body {
2529
font-family: 'Mona Sans Variable', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
30+
font-optical-sizing: auto;
31+
font-variant-ligatures: none;
2632
}
2733

2834
html {
@@ -47,7 +53,7 @@ html {
4753
margin: 0;
4854
flex: 1 1 auto;
4955
min-width: 0;
50-
font-size: 16px;
56+
font-size: 14px;
5157
font-weight: 600;
5258
}
5359
.site-title a {
@@ -284,8 +290,10 @@ html[data-color-mode="dark"] .menu-toggle-progress {
284290
}
285291
.markdown-body > details > .workshop-page-title {
286292
margin: 0;
287-
font-size: 32px;
288-
line-height: 1.25;
293+
max-width: 24ch;
294+
font-size: var(--workshop-type-title);
295+
font-weight: 400;
296+
line-height: 1.15;
289297
scroll-margin-top: var(--workshop-sticky-header-offset);
290298
}
291299

@@ -295,6 +303,34 @@ html[data-color-mode="dark"] .menu-toggle-progress {
295303
padding-inline: 20px !important;
296304
}
297305

306+
.markdown-body p,
307+
.markdown-body li {
308+
font-size: var(--workshop-type-body);
309+
line-height: 1.7;
310+
}
311+
.markdown-body p {
312+
max-width: 72ch;
313+
}
314+
.markdown-body h2:not(.workshop-page-title) {
315+
max-width: 24ch;
316+
font-size: var(--workshop-type-section);
317+
font-weight: 400;
318+
line-height: 1.2;
319+
}
320+
.markdown-body h3 {
321+
max-width: 24ch;
322+
font-size: var(--workshop-type-subheading);
323+
font-weight: 600;
324+
line-height: 1.3;
325+
}
326+
.markdown-body h4,
327+
.markdown-body h5,
328+
.markdown-body h6 {
329+
font-size: var(--workshop-type-body);
330+
font-weight: 600;
331+
line-height: 1.35;
332+
}
333+
298334
@media (min-width: 480px) {
299335
.markdown-body {
300336
padding-inline: 24px !important;
@@ -334,9 +370,6 @@ html[data-color-mode="dark"] .menu-toggle-progress {
334370
}
335371

336372
@media (max-width: 543px) {
337-
.markdown-body > details > .workshop-page-title {
338-
font-size: 28px;
339-
}
340373
.site-header {
341374
gap: 10px;
342375
padding: 0 12px;

0 commit comments

Comments
 (0)