Skip to content

Commit 12190aa

Browse files
committed
refactor(2048): render notes in semantic <main>, drop .prose wrapper
1 parent b36242f commit 12190aa

4 files changed

Lines changed: 47 additions & 74 deletions

File tree

examples/2048/design/serve.nu

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ def render-stories [slug: string]: nothing -> list {
355355
]
356356
"palettes" => (palette-catalog | each {|p| palette-story $p })
357357
"markdown" => [
358-
(story "rendered via .md, wrapped in .prose (same path as /notes pages)" [
359-
(DIV {class: "prose"} {__html: ($MD_SAMPLE | .md | get __html)})
358+
(story "rendered via .md; raw-tag typography (the /notes pages add the <main> column)" [
359+
{__html: ($MD_SAMPLE | .md | get __html)}
360360
])
361361
]
362362
_ => []
@@ -416,7 +416,7 @@ def design-page [req: record current: string]: nothing -> string {
416416
(A {href: $current} $entry.title)
417417
]
418418
--right [])
419-
(MAIN {class: "design-main"}
419+
(DIV {class: "design-main"}
420420
(NAV {class: "design-nav"}
421421
($CATALOG | each {|c|
422422
(A {href: $c.slug class: (if $c.slug == $current { "current" } else { "" })}

examples/2048/notes/serve.nu

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,13 @@ def all-pages []: nothing -> list {
4242
let root_req = $req | upsert mount_prefix ($req.mount_prefix | str replace -r '/notes$' '')
4343
let pages = all-pages
4444
([
45-
(DIV {class: "page"}
46-
(H1 "notes")
47-
(P "a wandering set of pages about 2048 -- the game, its history, and how this implementation works.")
48-
(UL ($pages | each {|p|
49-
(LI (A {href: ($req | href $"/($p.slug)")} $p.title))
50-
})))
45+
(H1 "notes")
46+
(P "a wandering set of pages about 2048 -- the game, its history, and how this implementation works.")
47+
(UL ($pages | each {|p|
48+
(LI (A {href: ($req | href $"/($p.slug)")} $p.title))
49+
}))
5150
] | layout $root_req $REV $DATASTAR_JS_PATH
52-
--title "nu2048 / notes"
53-
--body-class "notes")
51+
--title "nu2048 / notes")
5452
})
5553

5654
(route {method: GET path-matches: "/:slug"} {|req ctx|
@@ -61,12 +59,10 @@ def all-pages []: nothing -> list {
6159
let root_req = $req | upsert mount_prefix ($req.mount_prefix | str replace -r '/notes$' '')
6260
let rendered = $page.body | .md | get __html
6361
([
64-
(DIV {class: "page"}
65-
(H1 $page.title)
66-
(DIV {class: "prose"} {__html: $rendered}))
62+
(H1 $page.title)
63+
{__html: $rendered}
6764
] | layout $root_req $REV $DATASTAR_JS_PATH
68-
--title $"nu2048 / ($page.title)"
69-
--body-class "notes")
65+
--title $"nu2048 / ($page.title)")
7066
}
7167
})
7268
]

examples/2048/static/styles.css

Lines changed: 32 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,20 @@ html {
121121
body {
122122
display: flex;
123123
flex-direction: column;
124-
align-items: center;
125-
padding: 12px;
124+
max-width: 900px; /* the whole page is one centered column; */
125+
margin-inline: auto; /* html paints the full-viewport background */
126+
padding: 12px 1rem;
126127
gap: 12px;
127128
background: var(--bg);
128129
color: var(--fg);
129130
font: var(--text-md)/1.6 var(--font-sans);
130131
}
131132

132133
h1 { font-size: clamp(24px, 6vmin, 40px); }
133-
p { font-size: 14px; }
134+
/* Paragraphs inherit the body type (--text-md / 1.6). Secondary text
135+
that wants to be small opts in via a class (.hint, .credit, .by,
136+
...) rather than every paragraph opting out of the base size. */
137+
.hint { font-size: var(--text-sm); }
134138

135139
button {
136140
background: var(--accent);
@@ -309,9 +313,6 @@ body.flash-red { animation: flash-red 300ms ease; }
309313
}
310314

311315
.page {
312-
width: 100%;
313-
max-width: 900px;
314-
padding: 0 1rem;
315316
display: flex;
316317
flex-direction: column;
317318
gap: 1rem;
@@ -534,9 +535,6 @@ body.flash-red { animation: flash-red 300ms ease; }
534535
display: flex;
535536
flex-direction: column;
536537
gap: 1.5rem;
537-
max-width: 900px;
538-
width: 100%;
539-
padding: 0 1rem;
540538
margin: 1rem 0 2.5rem;
541539
}
542540
.hero > h2 { font-family: var(--font-mono); color: var(--fg-header); font-size: 3rem; line-height: 1.1; }
@@ -569,76 +567,57 @@ body.flash-red { animation: flash-red 300ms ease; }
569567
.callouts a { font-size: var(--text-lg); }
570568
.callout-desc { font-size: var(--text-md); opacity: 0.85; }
571569

572-
/* Article typography. Scoped to .prose so chrome (breadcrumbs, headers,
573-
sidebars) keeps its own type rules. Used by /notes pages and the
574-
/design markdown story. */
575-
.prose {
576-
max-width: 65ch;
577-
font-size: 1.2em; /* ~21.6px relative to body's 18px -- article body */
578-
line-height: 1.6;
579-
}
580-
.prose > * + * { margin-top: 1em; }
581-
.prose h2 {
582-
font-family: var(--font-mono);
583-
font-size: var(--text-xl);
584-
color: var(--fg-header);
585-
line-height: 1.2;
586-
margin-top: 2.5em;
587-
}
588-
.prose h3 {
589-
font-family: var(--font-mono);
590-
font-size: var(--text-lg);
591-
color: var(--fg-header);
592-
line-height: 1.2;
593-
margin-top: 2em;
594-
}
595-
.prose ul, .prose ol { padding-left: 1.5em; }
596-
.prose li + li { margin-top: 0.4em; }
597-
.prose li > p { margin: 0; } /* tight bullets, no double spacing */
598-
.prose blockquote {
599-
margin: 0;
570+
/* Raw-tag typography: the look lives on the tag so it reads the same
571+
wherever the tag appears (essays, the /design markdown demo, ...).
572+
Vertical rhythm (margins) is added per context below, not here, since
573+
the reset zeroes margins for the flex-based chrome.
574+
Headings share one look (the body's sans + off-white, like h1); each
575+
step just sizes down. The cream (--fg-header) is a specialization
576+
applied where wanted -- e.g. the splash hero's .hero > h2. */
577+
h2 { font-size: var(--text-xl); }
578+
h3 { font-size: var(--text-lg); }
579+
blockquote {
600580
padding: 0.25em 0 0.25em 1.25em;
601581
border-left: 3px solid var(--brand);
602582
color: var(--fg-header);
603583
font-style: italic;
604584
opacity: 0.9;
605585
}
606-
.prose code {
607-
/* element-rule already mono; just add a small pill background */
586+
code { /* mono is already set on the element; add the inline pill */
608587
font-size: 0.92em;
609588
padding: 0.1em 0.35em;
610589
background: rgba(0, 0, 0, 0.3);
611590
border-radius: 3px;
612591
}
613-
.prose pre {
614-
margin: 0;
592+
pre {
615593
padding: 0.9em 1.1em;
616594
background: rgba(0, 0, 0, 0.35);
617595
border-radius: 6px;
618596
overflow-x: auto;
619597
font-size: var(--text-sm);
620598
line-height: 1.5;
621599
}
622-
.prose pre code {
623-
/* inline-code styling shouldn't apply inside a <pre> */
624-
padding: 0;
625-
background: none;
626-
border-radius: 0;
627-
font-size: inherit;
628-
}
600+
pre code { padding: 0; background: none; border-radius: 0; font-size: inherit; }
601+
602+
/* Vertical rhythm for content blocks inside <main>. App pages put a
603+
single .page/.hero in main, so this is a no-op for them; essay pages
604+
(/notes) put their prose blocks straight in main, where it does the
605+
spacing. Direct-child (>) keeps the splash hero's nested h2 out of it. */
606+
main > * + * { margin-top: 1em; }
607+
/* Section breaks before headings, in rem so they don't compound with the
608+
heading's own (large) font-size the way em would. */
609+
main > h2 { margin-top: 2rem; }
610+
main > h3 { margin-top: 1.5rem; }
629611

630612
/* Site header: shared by / and /play. Mirrors the http-nu/www header
631613
pattern -- `flex items-baseline justify-between mt-10 mb-2`. Title
632614
left, status + credit right. No divider lines; whitespace separates. */
633615
.site-header {
634-
width: 100%;
635-
max-width: 900px;
636616
display: flex;
637617
align-items: baseline;
638618
justify-content: space-between;
639619
gap: 1rem;
640620
margin: 2rem 0 0.75rem;
641-
padding: 0 1rem;
642621
font-size: var(--text-sm);
643622
}
644623
.site-header .site-title {
@@ -673,12 +652,8 @@ body.flash-red { animation: flash-red 300ms ease; }
673652
/* Site footer: whitespace partitions, no border or background. Links
674653
like nav -- each page anchors the same set of meta destinations. */
675654
.site-footer {
676-
/* Same container shape as .page / .hero (body's align-items: center
677-
does the centering). Content right-aligned within. The link's
678-
muted look comes from the shared chrome-link rule. */
679-
width: 100%;
680-
max-width: 900px;
681-
padding: 0 1rem;
655+
/* Content right-aligned within the page column. The link's muted look
656+
comes from the shared chrome-link rule. */
682657
margin: 4rem 0 1.5rem;
683658
text-align: right;
684659
font-size: var(--text-sm);

examples/2048/tfe/templates/layout.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<div class="site-header-right">
2727
<a class="site-nav-link" href="{{ leaderboard_href }}">leaderboard</a>
2828
{% if sse %}<span class="site-presence" data-text="$presence.totalTabs + ' here'" title="people currently on the site"></span>{% endif %}
29-
{% if player_id %}<a class="you-are" href="{{ my_games_href }}" title="your games (profile soon)">you are: <code>{{ player_id }}</code></a>{% endif %}
29+
{% if player_id %}<a class="you-are" href="{{ my_games_href }}" title="your games (profile soon)">you are: {{ player_id }}</a>{% endif %}
3030
<div class="status">
3131
<span id="conn" class="stat"></span>
3232
{% if show_rtt %}<span id="rtt" class="stat"></span>{% endif %}
@@ -36,7 +36,9 @@
3636
</span>
3737
</div>
3838
</header>
39+
<main>
3940
{{ body_html | safe }}
41+
</main>
4042
<footer class="site-footer">
4143
<a href="{{ design_href }}">design</a>
4244
</footer>

0 commit comments

Comments
 (0)