Skip to content

Commit

Permalink
revised layout (#1682)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mbostock authored Sep 26, 2024
1 parent 28b857c commit c7dce79
Show file tree
Hide file tree
Showing 62 changed files with 135 additions and 89 deletions.
4 changes: 4 additions & 0 deletions docs/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ h1 {
font-weight: 500;
}

#observablehq-header {
container-type: inline-size;
}

@container not (min-width: 640px) {
.hide-if-small {
display: none;
Expand Down
6 changes: 2 additions & 4 deletions observablehq.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ export default {
: ""
}
<script type="module">/Win/.test(navigator.platform) || Array.from(document.querySelectorAll(".win"), (e) => e.remove())</script>`,
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);">
<a href="https://observablehq.com/" target="_self" rel="" style="display: flex; align-items: center;">
header: `<a href="https://observablehq.com/" target="_self" rel="" style="display: flex; align-items: center;">
<svg width="22" height="22" viewBox="0 0 21.92930030822754 22.68549919128418" fill="currentColor">
<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>
</svg>
Expand All @@ -136,8 +135,7 @@ export default {
stargazers_count ? formatPrefix(".1s", 1000)(stargazers_count) : ""
}</span></a>
</span>
</div>
</div>`,
</div>`,
footer: ${new Date().getUTCFullYear()} Observable, Inc.`,
style: "style.css",
search: {
Expand Down
4 changes: 2 additions & 2 deletions src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ import ${preview || page.code.length ? `{${preview ? "open, " : ""}define} from
${preview ? `\nopen({hash: ${JSON.stringify(resolvers.hash)}, eval: (body) => eval(body)});\n` : ""}${page.code
.map(({node, id, mode}) => `\n${transpileJavaScript(node, {id, path, params, mode, resolveImport})}`)
.join("")}`)}
</script>${sidebar ? html`\n${await renderSidebar(options, resolvers)}` : ""}${
</script>${sidebar ? html`\n${await renderSidebar(options, resolvers)}` : ""}
<div id="observablehq-center">${renderHeader(page.header, resolvers)}${
toc.show ? html`\n${renderToc(findHeaders(page), toc.label)}` : ""
}
<div id="observablehq-center">${renderHeader(page.header, resolvers)}
<main id="observablehq-main" class="observablehq${draft ? " observablehq--draft" : ""}">
${html.unsafe(rewriteHtml(page.body, resolvers))}</main>${renderFooter(page.footer, resolvers, options)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/style/grid.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#observablehq-center {
#observablehq-main {
container-type: inline-size;
}

Expand Down
88 changes: 66 additions & 22 deletions src/style/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,40 @@
--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");
--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");
--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");
--observablehq-max-width: 1440px;
--observablehq-header-height: 2.2rem;
}

body {
max-width: var(--observablehq-max-width);
margin: auto;
}

#observablehq-main,
#observablehq-header,
#observablehq-footer {
margin: 1rem auto;
max-width: 1152px;
}

#observablehq-header {
position: fixed;
top: 0;
left: calc(max(0rem, (100vw - var(--observablehq-max-width)) / 2) + var(--observablehq-inset-left) + 2rem);
right: calc(max(0rem, (100vw - var(--observablehq-max-width)) / 2) + var(--observablehq-inset-right) + 2rem);
z-index: 1;
display: flex;
align-items: center;
gap: 0.5rem;
height: var(--observablehq-header-height);
margin: 0 -2rem 2rem -2rem;
padding: 1rem 2rem 0.5rem 2rem;
background: var(--theme-background);
border-bottom: solid 1px var(--theme-foreground-faintest);
font: 500 16px var(--sans-serif);
}

#observablehq-main {
margin-top: 0.67rem;
min-height: calc(100vh - 20rem);
position: relative;
z-index: 0;
Expand Down Expand Up @@ -78,22 +102,26 @@

#observablehq-center {
margin: 1rem 2rem;
padding-top: calc(var(--observablehq-header-height) + 0.5rem);
--observablehq-inset-left: 0rem;
--observablehq-inset-right: 0rem;
}

#observablehq-sidebar {
--observablehq-sidebar-padding-left: calc(max(0rem, (100vw - var(--observablehq-max-width)) / 2));
position: fixed;
background: var(--theme-background-alt);
color: var(--theme-foreground-muted);
font: 14px var(--sans-serif);
visibility: hidden;
font-weight: 500;
width: 272px;
width: calc(272px + var(--observablehq-sidebar-padding-left));
z-index: 2;
top: 0;
bottom: 0;
left: -272px;
box-sizing: border-box;
padding: 0 0.5rem 1rem 0.5rem;
padding: 0 0.5rem 1rem calc(var(--observablehq-sidebar-padding-left) + 0.5rem);
overflow-y: auto;
}

Expand All @@ -117,16 +145,28 @@
position: sticky;
top: 0;
z-index: 1;
background: var(--theme-background-alt);
font-size: 16px;
font-weight: 700;
padding-top: 1rem;
padding-left: 0.5rem;
margin: 0;
margin-left: -0.5rem;
color: var(--theme-foreground);
}

#observablehq-sidebar > ol:first-child::before {
content: "";
position: absolute;
inset: 0 -0.5rem;
background: var(--theme-background-alt);
}

#observablehq-sidebar > ol:first-child > li {
position: relative;
}

#observablehq-sidebar > ol:first-child > li > a {
height: calc(var(--observablehq-header-height) - 1rem);
}

#observablehq-sidebar > ol:last-child,
#observablehq-sidebar > details:last-child,
#observablehq-sidebar > section:last-child {
Expand Down Expand Up @@ -193,7 +233,7 @@
top: 1rem;
right: 0;
width: 2rem;
height: 2.2rem;
height: var(--observablehq-header-height);
display: flex;
align-items: center;
justify-content: center;
Expand Down Expand Up @@ -250,8 +290,8 @@
color: var(--theme-foreground-muted);
font: 400 14px var(--sans-serif);
z-index: 1;
top: 0;
right: 0;
top: calc(var(--observablehq-header-height) + 1.5rem);
right: calc(max(0rem, (100% - var(--observablehq-max-width)) / 2) + 1rem);
bottom: 0;
overflow-y: auto;
}
Expand Down Expand Up @@ -358,17 +398,18 @@
left: 0;
visibility: initial;
box-shadow: none;
border-right: solid 1px var(--theme-foreground-faintest);
}
#observablehq-sidebar-toggle:checked ~ #observablehq-center,
#observablehq-sidebar-toggle:indeterminate ~ #observablehq-center {
padding-left: calc(272px + 1rem);
--observablehq-inset-left: calc(272px + 1rem);
--observablehq-inset-right: 1rem;
padding-left: var(--observablehq-inset-left);
padding-right: 1rem;
}
}

@media (min-width: calc(640px + 6rem + 192px)) {
#observablehq-toc ~ #observablehq-center {
@media (min-width: calc(640px + 5rem + 192px)) {
#observablehq-toc ~ #observablehq-main {
padding-right: calc(192px + 1rem);
}
#observablehq-toc {
Expand All @@ -377,21 +418,24 @@
}

@media (min-width: calc(640px + 6rem + 272px)) {
#observablehq-sidebar-toggle:checked ~ #observablehq-toc,
#observablehq-sidebar-toggle:indeterminate ~ #observablehq-toc {
#observablehq-sidebar-toggle:checked ~ #observablehq-center #observablehq-toc,
#observablehq-sidebar-toggle:indeterminate ~ #observablehq-center #observablehq-toc {
display: none;
}
#observablehq-sidebar-toggle:checked ~ #observablehq-center #observablehq-main,
#observablehq-sidebar-toggle:indeterminate ~ #observablehq-center #observablehq-main {
padding-right: 0;
}
}

@media (min-width: calc(640px + 6rem + 272px + 192px)) {
#observablehq-sidebar-toggle:checked ~ #observablehq-toc,
#observablehq-sidebar-toggle:indeterminate ~ #observablehq-toc,
@media (min-width: calc(640px + 7rem + 272px + 192px)) {
#observablehq-sidebar-toggle:checked ~ #observablehq-center #observablehq-toc,
#observablehq-sidebar-toggle:indeterminate ~ #observablehq-center #observablehq-toc,
#observablehq-toc {
display: block;
}
#observablehq-sidebar-toggle:checked ~ #observablehq-toc ~ #observablehq-center,
#observablehq-sidebar-toggle:indeterminate ~ #observablehq-toc ~ #observablehq-center,
#observablehq-toc ~ #observablehq-center {
#observablehq-sidebar-toggle:checked ~ #observablehq-center #observablehq-main,
#observablehq-sidebar-toggle:indeterminate ~ #observablehq-center #observablehq-main {
padding-right: calc(192px + 1rem);
}
}
Expand Down Expand Up @@ -539,7 +583,7 @@
position: absolute;
overflow-y: auto;
top: 6.5rem;
left: 0;
left: var(--observablehq-sidebar-padding-left);
right: 0.5rem;
bottom: 0;
}
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/404/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import "./_observablehq/client.00000001.js";

</script>
<div id="observablehq-center">
<aside id="observablehq-toc" data-selector="h1:not(:first-of-type)[id], h2:first-child[id], :not(h1) + h2[id]">
<nav>
</nav>
</aside>
<div id="observablehq-center">
<main id="observablehq-main" class="observablehq">
<h1 id="page-not-found" tabindex="-1"><a class="observablehq-header-anchor" href="#page-not-found">Page not found</a></h1>
<p>Sorry, but we can’t find the page you requested.</p>
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/archives.posix/tar.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@
</ol>
</nav>
<script>{/* redacted init script */}</script>
<div id="observablehq-center">
<aside id="observablehq-toc" data-selector="h1:not(:first-of-type)[id], h2:first-child[id], :not(h1) + h2[id]">
<nav>
</nav>
</aside>
<div id="observablehq-center">
<main id="observablehq-main" class="observablehq">
<h1 id="tar" tabindex="-1"><a class="observablehq-header-anchor" href="#tar">Tar</a></h1>
<div class="observablehq observablehq--block"><observablehq-loading></observablehq-loading><!--:d5134368:--></div>
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/archives.posix/zip.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
</ol>
</nav>
<script>{/* redacted init script */}</script>
<div id="observablehq-center">
<aside id="observablehq-toc" data-selector="h1:not(:first-of-type)[id], h2:first-child[id], :not(h1) + h2[id]">
<nav>
</nav>
</aside>
<div id="observablehq-center">
<main id="observablehq-main" class="observablehq">
<h1 id="zip" tabindex="-1"><a class="observablehq-header-anchor" href="#zip">Zip</a></h1>
<div class="observablehq observablehq--block"><observablehq-loading></observablehq-loading><!--:d3b9d0ee:--></div>
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/archives.win32/tar.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
</ol>
</nav>
<script>{/* redacted init script */}</script>
<div id="observablehq-center">
<aside id="observablehq-toc" data-selector="h1:not(:first-of-type)[id], h2:first-child[id], :not(h1) + h2[id]">
<nav>
</nav>
</aside>
<div id="observablehq-center">
<main id="observablehq-main" class="observablehq">
<h1 id="tar" tabindex="-1"><a class="observablehq-header-anchor" href="#tar">Tar</a></h1>
<div class="observablehq observablehq--block"><observablehq-loading></observablehq-loading><!--:d5134368:--></div>
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/archives.win32/zip.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
</ol>
</nav>
<script>{/* redacted init script */}</script>
<div id="observablehq-center">
<aside id="observablehq-toc" data-selector="h1:not(:first-of-type)[id], h2:first-child[id], :not(h1) + h2[id]">
<nav>
</nav>
</aside>
<div id="observablehq-center">
<main id="observablehq-main" class="observablehq">
<h1 id="zip" tabindex="-1"><a class="observablehq-header-anchor" href="#zip">Zip</a></h1>
<div class="observablehq observablehq--block"><observablehq-loading></observablehq-loading><!--:d3b9d0ee:--></div>
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/config/closed/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
</details>
</nav>
<script>{/* redacted init script */}</script>
<div id="observablehq-center">
<aside id="observablehq-toc" data-selector="h1:not(:first-of-type)[id], h2:first-child[id], :not(h1) + h2[id]">
<nav>
</nav>
</aside>
<div id="observablehq-center">
<main id="observablehq-main" class="observablehq">
<h1 id="a-page" tabindex="-1"><a class="observablehq-header-anchor" href="#a-page">A page…</a></h1>
<p>in a closed subsection.</p>
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/config/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
</details>
</nav>
<script>{/* redacted init script */}</script>
<div id="observablehq-center">
<aside id="observablehq-toc" data-selector="h1:not(:first-of-type)[id], h2:first-child[id], :not(h1) + h2[id]">
<nav>
</nav>
</aside>
<div id="observablehq-center">
<main id="observablehq-main" class="observablehq">
<h1 id="index" tabindex="-1"><a class="observablehq-header-anchor" href="#index">Index</a></h1>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/config/one.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
</details>
</nav>
<script>{/* redacted init script */}</script>
<div id="observablehq-center">
<aside id="observablehq-toc" data-selector="h1:not(:first-of-type)[id], h2:first-child[id], :not(h1) + h2[id]">
<nav>
</nav>
</aside>
<div id="observablehq-center">
<main id="observablehq-main" class="observablehq">
<h1 id="one" tabindex="-1"><a class="observablehq-header-anchor" href="#one">One</a></h1>
</main>
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/config/sub/two.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
</details>
</nav>
<script>{/* redacted init script */}</script>
<div id="observablehq-center">
<aside id="observablehq-toc" data-selector="h1:not(:first-of-type)[id], h2:first-child[id], :not(h1) + h2[id]">
<nav>
</nav>
</aside>
<div id="observablehq-center">
<main id="observablehq-main" class="observablehq">
<h1 id="two" tabindex="-1"><a class="observablehq-header-anchor" href="#two">Two</a></h1>
</main>
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/config/toc-override.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
</details>
</nav>
<script>{/* redacted init script */}</script>
<div id="observablehq-center">
<aside id="observablehq-toc" data-selector="h1:not(:first-of-type)[id], h2:first-child[id], :not(h1) + h2[id]">
<nav>
<div>dollar&amp;pound</div>
Expand All @@ -44,7 +45,6 @@
</ol>
</nav>
</aside>
<div id="observablehq-center">
<main id="observablehq-main" class="observablehq">
<h1 id="h1-section" tabindex="-1"><a class="observablehq-header-anchor" href="#h1-section">H1: Section</a></h1>
<h2 id="h2-section-1" tabindex="-1"><a class="observablehq-header-anchor" href="#h2-section-1">H2: Section 1</a></h2>
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/config/toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
</details>
</nav>
<script>{/* redacted init script */}</script>
<div id="observablehq-center">
<aside id="observablehq-toc" data-selector="h1:not(:first-of-type)[id], h2:first-child[id], :not(h1) + h2[id]">
<nav>
<div>On this page</div>
Expand All @@ -45,7 +46,6 @@
</ol>
</nav>
</aside>
<div id="observablehq-center">
<main id="observablehq-main" class="observablehq">
<h1 id="h1-section" tabindex="-1"><a class="observablehq-header-anchor" href="#h1-section">H1: Section</a></h1>
<h2 id="h2-section-1" tabindex="-1"><a class="observablehq-header-anchor" href="#h2-section-1">H2: Section 1</a></h2>
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/data-loaders/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
}});

</script>
<div id="observablehq-center">
<aside id="observablehq-toc" data-selector="h1:not(:first-of-type)[id], h2:first-child[id], :not(h1) + h2[id]">
<nav>
</nav>
</aside>
<div id="observablehq-center">
<main id="observablehq-main" class="observablehq">
<h1 id="data-loader-test" tabindex="-1"><a class="observablehq-header-anchor" href="#data-loader-test">Data loader test</a></h1>
<div class="observablehq observablehq--block"><!--:05e74070:--></div>
Expand Down
Loading

0 comments on commit c7dce79

Please sign in to comment.