Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move search into header #1687

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions observablehq.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,7 @@ export default {
: ""
}
<script type="module">/Win/.test(navigator.platform) || Array.from(document.querySelectorAll(".win"), (e) => e.remove())</script>`,
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>
</a>
<div style="display: flex; flex-grow: 1; justify-content: space-between; align-items: baseline;">
<a href="/">
<span class="hide-if-small">Observable</span> Framework
</a>
header: `<div style="display: flex; flex-grow: 1; justify-content: flex-end; align-items: baseline;">
<span style="display: flex; align-items: baseline; gap: 1rem; font-size: 14px;">
<a target="_blank" title="${
process.env.npm_package_version
Expand Down
15 changes: 8 additions & 7 deletions src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ ${preview ? `\nopen({hash: ${JSON.stringify(resolvers.hash)}, eval: (body) => ev
.map(({node, id, mode}) => `\n${transpileJavaScript(node, {id, path, params, mode, resolveImport})}`)
.join("")}`)}
</script>${sidebar ? html`\n${await renderSidebar(options, resolvers)}` : ""}
<div id="observablehq-center">${renderHeader(page.header, resolvers)}${
<div id="observablehq-center">${renderHeader(page.header, options, resolvers)}${
toc.show ? html`\n${renderToc(findHeaders(page), toc.label)}` : ""
}
<main id="observablehq-main" class="observablehq${draft ? " observablehq--draft" : ""}">
Expand Down Expand Up @@ -143,9 +143,8 @@ async function renderSidebar(options: RenderOptions, {resolveImport, resolveLink
}"><a href="${encodeURI(resolveLink("/"))}">${title}</a></li>
</ol>${
search
? html`\n <div id="observablehq-search"><input type="search" placeholder="Search"></div>
<div id="observablehq-search-results"></div>
<script>{${html.unsafe(
? html`\n <div id="observablehq-search-results"></div>
<script type="module">{${html.unsafe(
(await rollupClient(getClientPath("search-init.js"), root, path, {resolveImport, minify: true})).trim()
)}}</script>`
: ""
Expand Down Expand Up @@ -249,9 +248,11 @@ function renderModulePreload(href: string): Html | null {
return isJavaScript(href) ? html`\n<link rel="modulepreload" href="${href}">` : null;
}

function renderHeader(header: MarkdownPage["header"], resolvers: HtmlResolvers): Html | null {
return header
? html`\n<header id="observablehq-header">\n${html.unsafe(rewriteHtml(header, resolvers))}\n</header>`
function renderHeader(header: MarkdownPage["header"], {search}: RenderOptions, resolvers: HtmlResolvers): Html | null {
return header || search
? html`\n<header id="observablehq-header">${
search ? html`\n<div id="observablehq-search"><input type="search" placeholder="Search"></div>` : null
}${header ? html`\n${html.unsafe(rewriteHtml(header, resolvers))}` : null}\n</header>`
: null;
}

Expand Down
10 changes: 7 additions & 3 deletions src/style/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,6 @@ body {

#observablehq-search {
position: relative;
padding: 0.5rem 0 0 0;
display: flex;
align-items: center;
}
Expand All @@ -557,7 +556,7 @@ body {
width: 100%;
border: none;
border-radius: 4px;
background-color: var(--theme-background);
background-color: var(--theme-background-alt);
font-size: 13.3px;
height: 28px;
}
Expand All @@ -578,10 +577,15 @@ body {
pointer-events: none;
}

#observablehq-search:not(:focus-within)::before {
color: var(--theme-foreground-faint);
}

#observablehq-search::after {
position: absolute;
right: 6px;
content: attr(data-shortcut);
color: var(--theme-foreground-faint);
pointer-events: none;
}

Expand All @@ -593,7 +597,7 @@ body {
--relevance-width: 32px;
position: absolute;
overflow-y: auto;
top: 6.5rem;
top: calc(var(--observablehq-header-height) + 2rem);
left: var(--observablehq-sidebar-padding-left);
right: 0.5rem;
bottom: 0;
Expand Down
Loading