Skip to content

Commit

Permalink
explicit html, head, body (#1732)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock authored Oct 9, 2024
1 parent e8e590c commit ba59a5e
Show file tree
Hide file tree
Showing 59 changed files with 355 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export async function renderPage(page: MarkdownPage, options: RenderOptions & Re
const toc = mergeToc(data.toc, options.toc);
const {files, resolveFile, resolveImport} = resolvers;
return String(html`<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">${path === "/404" ? html`\n<base href="${preview ? "/" : base}">` : ""}
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="generator" content="Observable Framework v${process.env.npm_package_version}">
Expand Down Expand Up @@ -81,13 +83,17 @@ 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, resolveFile})}`)
.join("")}`)}
</script>${sidebar ? html`\n${await renderSidebar(options, resolvers)}` : ""}
</script>
</head>
<body>${sidebar ? html`\n${await renderSidebar(options, resolvers)}` : ""}
<div id="observablehq-center">${renderHeader(page.header, resolvers)}${
toc.show ? html`\n${renderToc(findHeaders(page), toc.label)}` : ""
}
<main id="observablehq-main" class="observablehq${draft ? " observablehq--draft" : ""}">
${html.unsafe(rewriteHtml(page.body, resolvers))}</main>${renderFooter(page.footer, resolvers, options)}
</div>
</body>
</html>
`);
}

Expand Down
6 changes: 6 additions & 0 deletions test/output/build/404/404.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
Expand All @@ -25,6 +27,8 @@
import "./_observablehq/client.00000001.js";

</script>
</head>
<body>
<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>
Expand All @@ -38,3 +42,5 @@ <h1 id="page-not-found" tabindex="-1"><a class="observablehq-header-anchor" href
<div>Built with <a href="https://observablehq.com/" target="_blank" rel="noopener noreferrer">Observable</a> on <a title="2024-01-10T16:00:00">Jan 10, 2024</a>.</div>
</footer>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions test/output/build/archives.posix/tar.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="generator" content="Observable Framework v1.0.0-test">
Expand Down Expand Up @@ -46,6 +48,8 @@
}});

</script>
</head>
<body>
<input id="observablehq-sidebar-toggle" type="checkbox" title="Toggle sidebar">
<label id="observablehq-sidebar-backdrop" for="observablehq-sidebar-toggle"></label>
<nav id="observablehq-sidebar">
Expand Down Expand Up @@ -76,3 +80,5 @@ <h1 id="tar" tabindex="-1"><a class="observablehq-header-anchor" href="#tar">Tar
<div>Built with <a href="https://observablehq.com/" target="_blank" rel="noopener noreferrer">Observable</a> on <a title="2024-01-10T16:00:00">Jan 10, 2024</a>.</div>
</footer>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions test/output/build/archives.posix/zip.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="generator" content="Observable Framework v1.0.0-test">
Expand Down Expand Up @@ -36,6 +38,8 @@
}});

</script>
</head>
<body>
<input id="observablehq-sidebar-toggle" type="checkbox" title="Toggle sidebar">
<label id="observablehq-sidebar-backdrop" for="observablehq-sidebar-toggle"></label>
<nav id="observablehq-sidebar">
Expand Down Expand Up @@ -65,3 +69,5 @@ <h1 id="zip" tabindex="-1"><a class="observablehq-header-anchor" href="#zip">Zip
<div>Built with <a href="https://observablehq.com/" target="_blank" rel="noopener noreferrer">Observable</a> on <a title="2024-01-10T16:00:00">Jan 10, 2024</a>.</div>
</footer>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions test/output/build/archives.win32/tar.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="generator" content="Observable Framework v1.0.0-test">
Expand Down Expand Up @@ -32,6 +34,8 @@
}});

</script>
</head>
<body>
<input id="observablehq-sidebar-toggle" type="checkbox" title="Toggle sidebar">
<label id="observablehq-sidebar-backdrop" for="observablehq-sidebar-toggle"></label>
<nav id="observablehq-sidebar">
Expand Down Expand Up @@ -60,3 +64,5 @@ <h1 id="tar" tabindex="-1"><a class="observablehq-header-anchor" href="#tar">Tar
<div>Built with <a href="https://observablehq.com/" target="_blank" rel="noopener noreferrer">Observable</a> on <a title="2024-01-10T16:00:00">Jan 10, 2024</a>.</div>
</footer>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions test/output/build/archives.win32/zip.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="generator" content="Observable Framework v1.0.0-test">
Expand All @@ -25,6 +27,8 @@
}});

</script>
</head>
<body>
<input id="observablehq-sidebar-toggle" type="checkbox" title="Toggle sidebar">
<label id="observablehq-sidebar-backdrop" for="observablehq-sidebar-toggle"></label>
<nav id="observablehq-sidebar">
Expand Down Expand Up @@ -52,3 +56,5 @@ <h1 id="zip" tabindex="-1"><a class="observablehq-header-anchor" href="#zip">Zip
<div>Built with <a href="https://observablehq.com/" target="_blank" rel="noopener noreferrer">Observable</a> on <a title="2024-01-10T16:00:00">Jan 10, 2024</a>.</div>
</footer>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions test/output/build/config/closed/page.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="generator" content="Observable Framework v1.0.0-test">
Expand All @@ -16,6 +18,8 @@
import "../_observablehq/client.00000001.js";

</script>
</head>
<body>
<input id="observablehq-sidebar-toggle" type="checkbox" title="Toggle sidebar">
<label id="observablehq-sidebar-backdrop" for="observablehq-sidebar-toggle"></label>
<nav id="observablehq-sidebar">
Expand Down Expand Up @@ -50,3 +54,5 @@ <h1 id="a-page" tabindex="-1"><a class="observablehq-header-anchor" href="#a-pag
<div>Built with <a href="https://observablehq.com/" target="_blank" rel="noopener noreferrer">Observable</a> on <a title="2024-01-10T16:00:00">Jan 10, 2024</a>.</div>
</footer>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions test/output/build/config/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="generator" content="Observable Framework v1.0.0-test">
Expand All @@ -16,6 +18,8 @@
import "./_observablehq/client.00000001.js";

</script>
</head>
<body>
<input id="observablehq-sidebar-toggle" type="checkbox" title="Toggle sidebar">
<label id="observablehq-sidebar-backdrop" for="observablehq-sidebar-toggle"></label>
<nav id="observablehq-sidebar">
Expand Down Expand Up @@ -53,3 +57,5 @@ <h1 id="index" tabindex="-1"><a class="observablehq-header-anchor" href="#index"
<div>Built with <a href="https://observablehq.com/" target="_blank" rel="noopener noreferrer">Observable</a> on <a title="2024-01-10T16:00:00">Jan 10, 2024</a>.</div>
</footer>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions test/output/build/config/one.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="generator" content="Observable Framework v1.0.0-test">
Expand All @@ -16,6 +18,8 @@
import "./_observablehq/client.00000001.js";

</script>
</head>
<body>
<input id="observablehq-sidebar-toggle" type="checkbox" title="Toggle sidebar">
<label id="observablehq-sidebar-backdrop" for="observablehq-sidebar-toggle"></label>
<nav id="observablehq-sidebar">
Expand Down Expand Up @@ -49,3 +53,5 @@ <h1 id="one" tabindex="-1"><a class="observablehq-header-anchor" href="#one">One
<div>Built with <a href="https://observablehq.com/" target="_blank" rel="noopener noreferrer">Observable</a> on <a title="2024-01-10T16:00:00">Jan 10, 2024</a>.</div>
</footer>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions test/output/build/config/sub/two.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="generator" content="Observable Framework v1.0.0-test">
Expand All @@ -16,6 +18,8 @@
import "../_observablehq/client.00000001.js";

</script>
</head>
<body>
<input id="observablehq-sidebar-toggle" type="checkbox" title="Toggle sidebar">
<label id="observablehq-sidebar-backdrop" for="observablehq-sidebar-toggle"></label>
<nav id="observablehq-sidebar">
Expand Down Expand Up @@ -49,3 +53,5 @@ <h1 id="two" tabindex="-1"><a class="observablehq-header-anchor" href="#two">Two
<div>Built with <a href="https://observablehq.com/" target="_blank" rel="noopener noreferrer">Observable</a> on <a title="2024-01-10T16:00:00">Jan 10, 2024</a>.</div>
</footer>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions test/output/build/config/toc-override.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="generator" content="Observable Framework v1.0.0-test">
Expand All @@ -16,6 +18,8 @@
import "./_observablehq/client.00000001.js";

</script>
</head>
<body>
<input id="observablehq-sidebar-toggle" type="checkbox" title="Toggle sidebar">
<label id="observablehq-sidebar-backdrop" for="observablehq-sidebar-toggle"></label>
<nav id="observablehq-sidebar">
Expand Down Expand Up @@ -57,3 +61,5 @@ <h3 id="h3-section-1" tabindex="-1"><a class="observablehq-header-anchor" href="
<div>Built with <a href="https://observablehq.com/" target="_blank" rel="noopener noreferrer">Observable</a> on <a title="2024-01-10T16:00:00">Jan 10, 2024</a>.</div>
</footer>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions test/output/build/config/toc.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="generator" content="Observable Framework v1.0.0-test">
Expand All @@ -16,6 +18,8 @@
import "./_observablehq/client.00000001.js";

</script>
</head>
<body>
<input id="observablehq-sidebar-toggle" type="checkbox" title="Toggle sidebar">
<label id="observablehq-sidebar-backdrop" for="observablehq-sidebar-toggle"></label>
<nav id="observablehq-sidebar">
Expand Down Expand Up @@ -59,3 +63,5 @@ <h2 id="h2-script-alert-1-script-not-nice" tabindex="-1"><a class="observablehq-
<div>Built with <a href="https://observablehq.com/" target="_blank" rel="noopener noreferrer">Observable</a> on <a title="2024-01-10T16:00:00">Jan 10, 2024</a>.</div>
</footer>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions test/output/build/data-loaders/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="generator" content="Observable Framework v1.0.0-test">
Expand Down Expand Up @@ -28,6 +30,8 @@
}});

</script>
</head>
<body>
<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>
Expand All @@ -41,3 +45,5 @@ <h1 id="data-loader-test" tabindex="-1"><a class="observablehq-header-anchor" hr
<div>Built with <a href="https://observablehq.com/" target="_blank" rel="noopener noreferrer">Observable</a> on <a title="2024-01-10T16:00:00">Jan 10, 2024</a>.</div>
</footer>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions test/output/build/draft/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="generator" content="Observable Framework v1.0.0-test">
Expand All @@ -16,6 +18,8 @@
import "./_observablehq/client.00000001.js";

</script>
</head>
<body>
<input id="observablehq-sidebar-toggle" type="checkbox" title="Toggle sidebar">
<label id="observablehq-sidebar-backdrop" for="observablehq-sidebar-toggle"></label>
<nav id="observablehq-sidebar">
Expand All @@ -42,3 +46,5 @@ <h1 id="draft-test" tabindex="-1"><a class="observablehq-header-anchor" href="#d
<div>Built with <a href="https://observablehq.com/" target="_blank" rel="noopener noreferrer">Observable</a> on <a title="2024-01-10T16:00:00">Jan 10, 2024</a>.</div>
</footer>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions test/output/build/draft/page-published.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="generator" content="Observable Framework v1.0.0-test">
Expand All @@ -16,6 +18,8 @@
import "./_observablehq/client.00000001.js";

</script>
</head>
<body>
<input id="observablehq-sidebar-toggle" type="checkbox" title="Toggle sidebar">
<label id="observablehq-sidebar-backdrop" for="observablehq-sidebar-toggle"></label>
<nav id="observablehq-sidebar">
Expand All @@ -42,3 +46,5 @@ <h1 id="this-is-for-real" tabindex="-1"><a class="observablehq-header-anchor" hr
<div>Built with <a href="https://observablehq.com/" target="_blank" rel="noopener noreferrer">Observable</a> on <a title="2024-01-10T16:00:00">Jan 10, 2024</a>.</div>
</footer>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions test/output/build/embed/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="generator" content="Observable Framework v1.0.0-test">
Expand All @@ -16,6 +18,8 @@
import "./_observablehq/client.00000001.js";

</script>
</head>
<body>
<input id="observablehq-sidebar-toggle" type="checkbox" title="Toggle sidebar">
<label id="observablehq-sidebar-backdrop" for="observablehq-sidebar-toggle"></label>
<nav id="observablehq-sidebar">
Expand Down Expand Up @@ -51,3 +55,5 @@ <h1 id="embeds" tabindex="-1"><a class="observablehq-header-anchor" href="#embed
<div>Built with <a href="https://observablehq.com/" target="_blank" rel="noopener noreferrer">Observable</a> on <a title="2024-01-10T16:00:00">Jan 10, 2024</a>.</div>
</footer>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions test/output/build/embed/w3c.js.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="generator" content="Observable Framework v1.0.0-test">
Expand All @@ -16,6 +18,8 @@
import "./_observablehq/client.00000001.js";

</script>
</head>
<body>
<input id="observablehq-sidebar-toggle" type="checkbox" title="Toggle sidebar">
<label id="observablehq-sidebar-backdrop" for="observablehq-sidebar-toggle"></label>
<nav id="observablehq-sidebar">
Expand Down Expand Up @@ -45,3 +49,5 @@ <h1 id="w3-c-js" tabindex="-1"><a class="observablehq-header-anchor" href="#w3-c
<div>Built with <a href="https://observablehq.com/" target="_blank" rel="noopener noreferrer">Observable</a> on <a title="2024-01-10T16:00:00">Jan 10, 2024</a>.</div>
</footer>
</div>
</body>
</html>
Loading

0 comments on commit ba59a5e

Please sign in to comment.