Skip to content

configurable footer #450

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

Merged
merged 2 commits into from
Jan 8, 2024
Merged
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
4 changes: 4 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ The pages list should _not_ include the root page, `index.md`. Also, we don’t

Whether to show the previous & next footer links; defaults to true.

## footer

An HTML fragment to add to the footer. Defaults to `Built with Observable`.

## toc

The table of contents configuration.
Expand Down
3 changes: 2 additions & 1 deletion observablehq.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ export default {
]
},
{name: "Contributing", path: "/contributing"}
]
],
footer: `© ${new Date().getUTCFullYear()} Observable, Inc.`
};
8 changes: 6 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface Config {
title?: string;
pages: (Page | Section)[]; // TODO rename to sidebar?
pager: boolean; // defaults to true
footer: string;
toc: TableOfContents;
style: null | Style; // defaults to {theme: ["auto"]}
deploy: null | {workspace: string; project: string};
Expand Down Expand Up @@ -65,8 +66,10 @@ async function readPages(root: string): Promise<Page[]> {
return pages;
}

const DEFAULT_FOOTER = 'Built with <a href="https://observablehq.com/" target=_blank>Observable</a>';

export async function normalizeConfig(spec: any = {}, defaultRoot = "docs"): Promise<Config> {
let {root = defaultRoot, output = "dist", style, theme = "auto", deploy} = spec;
let {root = defaultRoot, output = "dist", style, theme = "auto", deploy, footer = DEFAULT_FOOTER} = spec;
root = String(root);
output = String(output);
if (style === null) style = null;
Expand All @@ -76,9 +79,10 @@ export async function normalizeConfig(spec: any = {}, defaultRoot = "docs"): Pro
if (title !== undefined) title = String(title);
pages = Array.from(pages, normalizePageOrSection);
pager = Boolean(pager);
footer = String(footer);
toc = normalizeToc(toc);
deploy = deploy ? {workspace: String(deploy.workspace), project: String(deploy.project)} : null;
return {root, output, title, pages, pager, toc, style, deploy};
return {root, output, title, pages, pager, footer, toc, style, deploy};
}

function normalizeTheme(spec: any): string[] {
Expand Down
12 changes: 8 additions & 4 deletions src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,15 @@ function renderModulePreload(href: string): Html {
return html`\n<link rel="modulepreload" href="${href}"${integrity ? html` integrity="${integrity}"` : ""}>`;
}

function renderFooter(path: string, options: Pick<Config, "pages" | "pager" | "title">): Html {
function renderFooter(path: string, options: Pick<Config, "pages" | "pager" | "title" | "footer">): Html {
const link = options.pager ? findLink(path, options) : null;
return html`<footer id="observablehq-footer">${link ? renderPager(path, link) : ""}
<div>© ${new Date().getUTCFullYear()} Observable, Inc.</div>
</footer>`;
const footer = options.footer;
return link || footer
? html`<footer id="observablehq-footer">${link ? renderPager(path, link) : ""}${
footer ? html`\n<div>${html.unsafe(options.footer)}</div>` : ""
}
</footer>`
: html``;
}

function renderPager(path: string, {prev, next}: PageLink): Html {
Expand Down
2 changes: 2 additions & 0 deletions test/config-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe("readConfig(undefined, root)", () => {
title: undefined,
toc: {label: "On this page", show: true},
pager: true,
footer: 'Built with <a href="https://observablehq.com/" target=_blank>Observable</a>',
deploy: {
workspace: "acme",
project: "bi"
Expand All @@ -33,6 +34,7 @@ describe("readConfig(undefined, root)", () => {
title: undefined,
toc: {label: "Contents", show: true},
pager: true,
footer: 'Built with <a href="https://observablehq.com/" target=_blank>Observable</a>',
deploy: null
});
});
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 @@ -34,6 +34,6 @@ <h1 id="page-not-found" tabindex="-1"><a class="observablehq-header-anchor" href
<p>Sorry, but we can’t find the page you requested.</p>
</main>
<footer id="observablehq-footer">
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/archives/tar.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ <h1 id="tar" tabindex="-1"><a class="observablehq-header-anchor" href="#tar">Tar
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="./"><span>Home</span></a><a rel="next" href="./zip"><span>Zip</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/archives/zip.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ <h1 id="zip" tabindex="-1"><a class="observablehq-header-anchor" href="#zip">Zip
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="./tar"><span>Tar</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
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 @@ -45,6 +45,6 @@ <h1 id="a-page%E2%80%A6" tabindex="-1"><a class="observablehq-header-anchor" hre
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="../sub/two"><span>Two</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/config/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ <h1 id="index" tabindex="-1"><a class="observablehq-header-anchor" href="#index"
</main>
<footer id="observablehq-footer">
<nav><a rel="next" href="./one"><span>One&lt;Two</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/config/one.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ <h1 id="one" tabindex="-1"><a class="observablehq-header-anchor" href="#one">One
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="./"><span>Home</span></a><a rel="next" href="./sub/two"><span>Two</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
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 @@ -44,6 +44,6 @@ <h1 id="two" tabindex="-1"><a class="observablehq-header-anchor" href="#two">Two
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="../one"><span>One&lt;Two</span></a><a rel="next" href="../closed/page"><span>Closed page</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
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 @@ -52,6 +52,6 @@ <h2 id="h2%3A-section-2" tabindex="-1"><a class="observablehq-header-anchor" hre
<h3 id="h3%3A-section-1" tabindex="-1"><a class="observablehq-header-anchor" href="#h3%3A-section-1">H3: Section 1</a></h3>
</main>
<footer id="observablehq-footer">
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/config/toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ <h3 id="h3%3A-section-1" tabindex="-1"><a class="observablehq-header-anchor" hre
<h2 id="h2-%3Cscript%3Ealert(1)%3C%2Fscript%3E-not-nice" tabindex="-1"><a class="observablehq-header-anchor" href="#h2-%3Cscript%3Ealert(1)%3C%2Fscript%3E-not-nice">H2 &lt;script&gt;alert(1)&lt;/script&gt; not nice</a></h2>
</main>
<footer id="observablehq-footer">
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/fetches/foo.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ <h1 id="top" tabindex="-1"><a class="observablehq-header-anchor" href="#top">Top
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="./"><span>Home</span></a><a rel="next" href="./top"><span>Top</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/fetches/top.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ <h1 id="top" tabindex="-1"><a class="observablehq-header-anchor" href="#top">Top
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="./foo"><span>Top</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/files/files.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="./"><span>Home</span></a><a rel="next" href="./subsection/subfiles"><span>Untitled</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/files/subsection/subfiles.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="../files"><span>Untitled</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/imports/foo/foo.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ <h1 id="foo" tabindex="-1"><a class="observablehq-header-anchor" href="#foo">Foo
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="../"><span>Home</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/missing-file/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ <h1 id="build-test-case" tabindex="-1"><a class="observablehq-header-anchor" hre
<div id="cell-5760fd93" class="observablehq observablehq--block"></div>
</main>
<footer id="observablehq-footer">
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/missing-import/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ <h1 id="build-test-case" tabindex="-1"><a class="observablehq-header-anchor" hre
<div id="cell-e0627979" class="observablehq observablehq--block"></div>
</main>
<footer id="observablehq-footer">
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/multi/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ <h1 id="multi-test" tabindex="-1"><a class="observablehq-header-anchor" href="#m
</main>
<footer id="observablehq-footer">
<nav><a rel="next" href="./subsection/"><span>Sub-Section</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/multi/subsection/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ <h1 id="sub-section" tabindex="-1"><a class="observablehq-header-anchor" href="#
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="../"><span>Home</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/pager/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ <h1 id="index" tabindex="-1"><a class="observablehq-header-anchor" href="#index"
</main>
<footer id="observablehq-footer">
<nav><a rel="next" href="./sub/page0"><span>Page 0</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/pager/sub/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
<h1 id="subindex" tabindex="-1"><a class="observablehq-header-anchor" href="#subindex">subindex</a></h1>
</main>
<footer id="observablehq-footer">
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/pager/sub/page0.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ <h1 id="page-0" tabindex="-1"><a class="observablehq-header-anchor" href="#page-
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="../"><span>Home</span></a><a rel="next" href="./page1?x=1"><span>Page 1 ?x=1</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/pager/sub/page1..10.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
<h1 id="page-1..10" tabindex="-1"><a class="observablehq-header-anchor" href="#page-1..10">page 1..10</a></h1>
</main>
<footer id="observablehq-footer">
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/pager/sub/page1.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ <h1 id="page-1" tabindex="-1"><a class="observablehq-header-anchor" href="#page-
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="./page0"><span>Page 0</span></a><a rel="next" href="./page2"><span>Page 2</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/pager/sub/page2.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ <h1 id="page-2" tabindex="-1"><a class="observablehq-header-anchor" href="#page-
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="./page1?x=1"><span>Page 1 ?x=1</span></a><a rel="next" href="./page3?x=1"><span>Page 3 ?x=1</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/pager/sub/page3.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ <h1 id="page-3" tabindex="-1"><a class="observablehq-header-anchor" href="#page-
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="./page2"><span>Page 2</span></a><a rel="next" href="./page4"><span>Page 4</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/pager/sub/page4.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ <h1 id="page-4" tabindex="-1"><a class="observablehq-header-anchor" href="#page-
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="./page3?x=1"><span>Page 3 ?x=1</span></a><a rel="next" href="./page5#hello"><span>Page 5 #hello</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/pager/sub/page5.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ <h1 id="page-5" tabindex="-1"><a class="observablehq-header-anchor" href="#page-
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="./page4"><span>Page 4</span></a><a rel="next" href="./page6"><span>Page 6</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/pager/sub/page6.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ <h1 id="page-6" tabindex="-1"><a class="observablehq-header-anchor" href="#page-
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="./page5#hello"><span>Page 5 #hello</span></a><a rel="next" href="./page7"><span>Page 7</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/pager/sub/page7.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ <h1 id="page-7" tabindex="-1"><a class="observablehq-header-anchor" href="#page-
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="./page6"><span>Page 6</span></a><a rel="next" href="./page8"><span>Page 8</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/pager/sub/page8.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ <h1 id="page-8" tabindex="-1"><a class="observablehq-header-anchor" href="#page-
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="./page7"><span>Page 7</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/simple-public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ <h1 id="build-test-case" tabindex="-1"><a class="observablehq-header-anchor" hre
<p>Hello, world!</p>
</main>
<footer id="observablehq-footer">
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/simple/simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ <h1 id="build-test-case" tabindex="-1"><a class="observablehq-header-anchor" hre
</main>
<footer id="observablehq-footer">
<nav><a rel="prev" href="./"><span>Home</span></a></nav>
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>
2 changes: 1 addition & 1 deletion test/output/build/subtitle/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ <h2 id="third-section" tabindex="-1"><a class="observablehq-header-anchor" href=
<p>The third section is part of the TOC.</p>
</main>
<footer id="observablehq-footer">
<div>© 2024 Observable, Inc.</div>
<div>Built with <a href="https://observablehq.com/" target=_blank>Observable</a></div>
</footer>
</div>