Skip to content

Commit c7dce79

Browse files
authored
revised layout (#1682)
* revised layout * fix negative sidebar padding * tweak inset-right * cleaner * move container-type to main * fix search results inset * move header styles to default layout * update test snapshots * prettier * fix table of contents layout * reduce max-width to 1440px * remove sidebar border * fix home border alignment * fix toc top * tiny layout tweaks * fix hide-if-small * fix sidebar scroll, custom header height
1 parent 28b857c commit c7dce79

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+135
-89
lines changed

docs/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ h1 {
9999
font-weight: 500;
100100
}
101101

102+
#observablehq-header {
103+
container-type: inline-size;
104+
}
105+
102106
@container not (min-width: 640px) {
103107
.hide-if-small {
104108
display: none;

observablehq.config.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ export default {
114114
: ""
115115
}
116116
<script type="module">/Win/.test(navigator.platform) || Array.from(document.querySelectorAll(".win"), (e) => e.remove())</script>`,
117-
header: `<div style="display: flex; align-items: center; gap: 0.5rem; height: 2.2rem; margin: -1.5rem -2rem 2rem -2rem; padding: 0.5rem 2rem; border-bottom: solid 1px var(--theme-foreground-faintest); font: 500 16px var(--sans-serif);">
118-
<a href="https://observablehq.com/" target="_self" rel="" style="display: flex; align-items: center;">
117+
header: `<a href="https://observablehq.com/" target="_self" rel="" style="display: flex; align-items: center;">
119118
<svg width="22" height="22" viewBox="0 0 21.92930030822754 22.68549919128418" fill="currentColor">
120119
<path d="M10.9646 18.9046C9.95224 18.9046 9.07507 18.6853 8.33313 18.2467C7.59386 17.8098 7.0028 17.1909 6.62722 16.4604C6.22789 15.7003 5.93558 14.8965 5.75735 14.0684C5.56825 13.1704 5.47613 12.2574 5.48232 11.3427C5.48232 10.6185 5.52984 9.92616 5.62578 9.26408C5.7208 8.60284 5.89715 7.93067 6.15391 7.24843C6.41066 6.56618 6.74143 5.97468 7.14438 5.47308C7.56389 4.9592 8.1063 4.54092 8.72969 4.25059C9.38391 3.93719 10.1277 3.78091 10.9646 3.78091C11.977 3.78091 12.8542 4.00021 13.5962 4.43879C14.3354 4.87564 14.9265 5.49454 15.3021 6.22506C15.6986 6.97704 15.9883 7.7744 16.1719 8.61712C16.3547 9.459 16.447 10.3681 16.447 11.3427C16.447 12.067 16.3995 12.7593 16.3035 13.4214C16.2013 14.1088 16.0206 14.7844 15.7644 15.437C15.4994 16.1193 15.1705 16.7108 14.7739 17.2124C14.3774 17.714 13.8529 18.1215 13.1996 18.4349C12.5463 18.7483 11.8016 18.9046 10.9646 18.9046ZM12.8999 13.3447C13.4242 12.8211 13.7159 12.0966 13.7058 11.3427C13.7058 10.5639 13.4436 9.89654 12.92 9.34074C12.3955 8.78495 11.7441 8.50705 10.9646 8.50705C10.1852 8.50705 9.53376 8.78495 9.00928 9.34074C8.49569 9.87018 8.21207 10.5928 8.22348 11.3427C8.22348 12.1216 8.48572 12.7889 9.00928 13.3447C9.53376 13.9005 10.1852 14.1784 10.9646 14.1784C11.7441 14.1784 12.3891 13.9005 12.8999 13.3447ZM10.9646 22.6855C17.0199 22.6855 21.9293 17.6068 21.9293 11.3427C21.9293 5.07871 17.0199 0 10.9646 0C4.90942 0 0 5.07871 0 11.3427C0 17.6068 4.90942 22.6855 10.9646 22.6855Z"></path>
121120
</svg>
@@ -136,8 +135,7 @@ export default {
136135
stargazers_count ? formatPrefix(".1s", 1000)(stargazers_count) : ""
137136
}</span></a>
138137
</span>
139-
</div>
140-
</div>`,
138+
</div>`,
141139
footer: ${new Date().getUTCFullYear()} Observable, Inc.`,
142140
style: "style.css",
143141
search: {

src/render.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ import ${preview || page.code.length ? `{${preview ? "open, " : ""}define} from
8181
${preview ? `\nopen({hash: ${JSON.stringify(resolvers.hash)}, eval: (body) => eval(body)});\n` : ""}${page.code
8282
.map(({node, id, mode}) => `\n${transpileJavaScript(node, {id, path, params, mode, resolveImport})}`)
8383
.join("")}`)}
84-
</script>${sidebar ? html`\n${await renderSidebar(options, resolvers)}` : ""}${
84+
</script>${sidebar ? html`\n${await renderSidebar(options, resolvers)}` : ""}
85+
<div id="observablehq-center">${renderHeader(page.header, resolvers)}${
8586
toc.show ? html`\n${renderToc(findHeaders(page), toc.label)}` : ""
8687
}
87-
<div id="observablehq-center">${renderHeader(page.header, resolvers)}
8888
<main id="observablehq-main" class="observablehq${draft ? " observablehq--draft" : ""}">
8989
${html.unsafe(rewriteHtml(page.body, resolvers))}</main>${renderFooter(page.footer, resolvers, options)}
9090
</div>

src/style/grid.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#observablehq-center {
1+
#observablehq-main {
22
container-type: inline-size;
33
}
44

src/style/layout.css

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,40 @@
22
--theme-caret: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M5 7L8.125 9.5L11.25 7' stroke='black' stroke-width='1.5' stroke-linecap='round' fill='none'/%3E%3C/svg%3E");
33
--theme-toggle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='m10.5,11 2.5-3-2.5-3 M6,8h7' fill='none' stroke='black' stroke-width='2'/%3E%3Crect x='2' y='2' fill='currentColor' height='12' rx='0.5' width='2'/%3E%3C/svg%3E");
44
--theme-magnifier: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath stroke='currentColor' stroke-width='2' fill='none' d='M15,15L10.5,10.5a3,3 0 1,0 -6 -6a3,3 0 1,0 6 6'%3E%3C/path%3E%3C/svg%3E");
5+
--observablehq-max-width: 1440px;
6+
--observablehq-header-height: 2.2rem;
7+
}
8+
9+
body {
10+
max-width: var(--observablehq-max-width);
11+
margin: auto;
512
}
613

714
#observablehq-main,
815
#observablehq-header,
916
#observablehq-footer {
1017
margin: 1rem auto;
11-
max-width: 1152px;
18+
}
19+
20+
#observablehq-header {
21+
position: fixed;
22+
top: 0;
23+
left: calc(max(0rem, (100vw - var(--observablehq-max-width)) / 2) + var(--observablehq-inset-left) + 2rem);
24+
right: calc(max(0rem, (100vw - var(--observablehq-max-width)) / 2) + var(--observablehq-inset-right) + 2rem);
25+
z-index: 1;
26+
display: flex;
27+
align-items: center;
28+
gap: 0.5rem;
29+
height: var(--observablehq-header-height);
30+
margin: 0 -2rem 2rem -2rem;
31+
padding: 1rem 2rem 0.5rem 2rem;
32+
background: var(--theme-background);
33+
border-bottom: solid 1px var(--theme-foreground-faintest);
34+
font: 500 16px var(--sans-serif);
1235
}
1336

1437
#observablehq-main {
38+
margin-top: 0.67rem;
1539
min-height: calc(100vh - 20rem);
1640
position: relative;
1741
z-index: 0;
@@ -78,22 +102,26 @@
78102

79103
#observablehq-center {
80104
margin: 1rem 2rem;
105+
padding-top: calc(var(--observablehq-header-height) + 0.5rem);
106+
--observablehq-inset-left: 0rem;
107+
--observablehq-inset-right: 0rem;
81108
}
82109

83110
#observablehq-sidebar {
111+
--observablehq-sidebar-padding-left: calc(max(0rem, (100vw - var(--observablehq-max-width)) / 2));
84112
position: fixed;
85113
background: var(--theme-background-alt);
86114
color: var(--theme-foreground-muted);
87115
font: 14px var(--sans-serif);
88116
visibility: hidden;
89117
font-weight: 500;
90-
width: 272px;
118+
width: calc(272px + var(--observablehq-sidebar-padding-left));
91119
z-index: 2;
92120
top: 0;
93121
bottom: 0;
94122
left: -272px;
95123
box-sizing: border-box;
96-
padding: 0 0.5rem 1rem 0.5rem;
124+
padding: 0 0.5rem 1rem calc(var(--observablehq-sidebar-padding-left) + 0.5rem);
97125
overflow-y: auto;
98126
}
99127

@@ -117,16 +145,28 @@
117145
position: sticky;
118146
top: 0;
119147
z-index: 1;
120-
background: var(--theme-background-alt);
121148
font-size: 16px;
122149
font-weight: 700;
123150
padding-top: 1rem;
124-
padding-left: 0.5rem;
125151
margin: 0;
126-
margin-left: -0.5rem;
127152
color: var(--theme-foreground);
128153
}
129154

155+
#observablehq-sidebar > ol:first-child::before {
156+
content: "";
157+
position: absolute;
158+
inset: 0 -0.5rem;
159+
background: var(--theme-background-alt);
160+
}
161+
162+
#observablehq-sidebar > ol:first-child > li {
163+
position: relative;
164+
}
165+
166+
#observablehq-sidebar > ol:first-child > li > a {
167+
height: calc(var(--observablehq-header-height) - 1rem);
168+
}
169+
130170
#observablehq-sidebar > ol:last-child,
131171
#observablehq-sidebar > details:last-child,
132172
#observablehq-sidebar > section:last-child {
@@ -193,7 +233,7 @@
193233
top: 1rem;
194234
right: 0;
195235
width: 2rem;
196-
height: 2.2rem;
236+
height: var(--observablehq-header-height);
197237
display: flex;
198238
align-items: center;
199239
justify-content: center;
@@ -250,8 +290,8 @@
250290
color: var(--theme-foreground-muted);
251291
font: 400 14px var(--sans-serif);
252292
z-index: 1;
253-
top: 0;
254-
right: 0;
293+
top: calc(var(--observablehq-header-height) + 1.5rem);
294+
right: calc(max(0rem, (100% - var(--observablehq-max-width)) / 2) + 1rem);
255295
bottom: 0;
256296
overflow-y: auto;
257297
}
@@ -358,17 +398,18 @@
358398
left: 0;
359399
visibility: initial;
360400
box-shadow: none;
361-
border-right: solid 1px var(--theme-foreground-faintest);
362401
}
363402
#observablehq-sidebar-toggle:checked ~ #observablehq-center,
364403
#observablehq-sidebar-toggle:indeterminate ~ #observablehq-center {
365-
padding-left: calc(272px + 1rem);
404+
--observablehq-inset-left: calc(272px + 1rem);
405+
--observablehq-inset-right: 1rem;
406+
padding-left: var(--observablehq-inset-left);
366407
padding-right: 1rem;
367408
}
368409
}
369410

370-
@media (min-width: calc(640px + 6rem + 192px)) {
371-
#observablehq-toc ~ #observablehq-center {
411+
@media (min-width: calc(640px + 5rem + 192px)) {
412+
#observablehq-toc ~ #observablehq-main {
372413
padding-right: calc(192px + 1rem);
373414
}
374415
#observablehq-toc {
@@ -377,21 +418,24 @@
377418
}
378419

379420
@media (min-width: calc(640px + 6rem + 272px)) {
380-
#observablehq-sidebar-toggle:checked ~ #observablehq-toc,
381-
#observablehq-sidebar-toggle:indeterminate ~ #observablehq-toc {
421+
#observablehq-sidebar-toggle:checked ~ #observablehq-center #observablehq-toc,
422+
#observablehq-sidebar-toggle:indeterminate ~ #observablehq-center #observablehq-toc {
382423
display: none;
383424
}
425+
#observablehq-sidebar-toggle:checked ~ #observablehq-center #observablehq-main,
426+
#observablehq-sidebar-toggle:indeterminate ~ #observablehq-center #observablehq-main {
427+
padding-right: 0;
428+
}
384429
}
385430

386-
@media (min-width: calc(640px + 6rem + 272px + 192px)) {
387-
#observablehq-sidebar-toggle:checked ~ #observablehq-toc,
388-
#observablehq-sidebar-toggle:indeterminate ~ #observablehq-toc,
431+
@media (min-width: calc(640px + 7rem + 272px + 192px)) {
432+
#observablehq-sidebar-toggle:checked ~ #observablehq-center #observablehq-toc,
433+
#observablehq-sidebar-toggle:indeterminate ~ #observablehq-center #observablehq-toc,
389434
#observablehq-toc {
390435
display: block;
391436
}
392-
#observablehq-sidebar-toggle:checked ~ #observablehq-toc ~ #observablehq-center,
393-
#observablehq-sidebar-toggle:indeterminate ~ #observablehq-toc ~ #observablehq-center,
394-
#observablehq-toc ~ #observablehq-center {
437+
#observablehq-sidebar-toggle:checked ~ #observablehq-center #observablehq-main,
438+
#observablehq-sidebar-toggle:indeterminate ~ #observablehq-center #observablehq-main {
395439
padding-right: calc(192px + 1rem);
396440
}
397441
}
@@ -539,7 +583,7 @@
539583
position: absolute;
540584
overflow-y: auto;
541585
top: 6.5rem;
542-
left: 0;
586+
left: var(--observablehq-sidebar-padding-left);
543587
right: 0.5rem;
544588
bottom: 0;
545589
}

test/output/build/404/404.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
import "./_observablehq/client.00000001.js";
2626

2727
</script>
28+
<div id="observablehq-center">
2829
<aside id="observablehq-toc" data-selector="h1:not(:first-of-type)[id], h2:first-child[id], :not(h1) + h2[id]">
2930
<nav>
3031
</nav>
3132
</aside>
32-
<div id="observablehq-center">
3333
<main id="observablehq-main" class="observablehq">
3434
<h1 id="page-not-found" tabindex="-1"><a class="observablehq-header-anchor" href="#page-not-found">Page not found</a></h1>
3535
<p>Sorry, but we can’t find the page you requested.</p>

test/output/build/archives.posix/tar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@
5959
</ol>
6060
</nav>
6161
<script>{/* redacted init script */}</script>
62+
<div id="observablehq-center">
6263
<aside id="observablehq-toc" data-selector="h1:not(:first-of-type)[id], h2:first-child[id], :not(h1) + h2[id]">
6364
<nav>
6465
</nav>
6566
</aside>
66-
<div id="observablehq-center">
6767
<main id="observablehq-main" class="observablehq">
6868
<h1 id="tar" tabindex="-1"><a class="observablehq-header-anchor" href="#tar">Tar</a></h1>
6969
<div class="observablehq observablehq--block"><observablehq-loading></observablehq-loading><!--:d5134368:--></div>

test/output/build/archives.posix/zip.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@
4949
</ol>
5050
</nav>
5151
<script>{/* redacted init script */}</script>
52+
<div id="observablehq-center">
5253
<aside id="observablehq-toc" data-selector="h1:not(:first-of-type)[id], h2:first-child[id], :not(h1) + h2[id]">
5354
<nav>
5455
</nav>
5556
</aside>
56-
<div id="observablehq-center">
5757
<main id="observablehq-main" class="observablehq">
5858
<h1 id="zip" tabindex="-1"><a class="observablehq-header-anchor" href="#zip">Zip</a></h1>
5959
<div class="observablehq observablehq--block"><observablehq-loading></observablehq-loading><!--:d3b9d0ee:--></div>

test/output/build/archives.win32/tar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545
</ol>
4646
</nav>
4747
<script>{/* redacted init script */}</script>
48+
<div id="observablehq-center">
4849
<aside id="observablehq-toc" data-selector="h1:not(:first-of-type)[id], h2:first-child[id], :not(h1) + h2[id]">
4950
<nav>
5051
</nav>
5152
</aside>
52-
<div id="observablehq-center">
5353
<main id="observablehq-main" class="observablehq">
5454
<h1 id="tar" tabindex="-1"><a class="observablehq-header-anchor" href="#tar">Tar</a></h1>
5555
<div class="observablehq observablehq--block"><observablehq-loading></observablehq-loading><!--:d5134368:--></div>

test/output/build/archives.win32/zip.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838
</ol>
3939
</nav>
4040
<script>{/* redacted init script */}</script>
41+
<div id="observablehq-center">
4142
<aside id="observablehq-toc" data-selector="h1:not(:first-of-type)[id], h2:first-child[id], :not(h1) + h2[id]">
4243
<nav>
4344
</nav>
4445
</aside>
45-
<div id="observablehq-center">
4646
<main id="observablehq-main" class="observablehq">
4747
<h1 id="zip" tabindex="-1"><a class="observablehq-header-anchor" href="#zip">Zip</a></h1>
4848
<div class="observablehq observablehq--block"><observablehq-loading></observablehq-loading><!--:d3b9d0ee:--></div>

0 commit comments

Comments
 (0)