diff --git a/docs/config.md b/docs/config.md index ec0847b93..64c9a331b 100644 --- a/docs/config.md +++ b/docs/config.md @@ -106,6 +106,10 @@ In this case, the path to the stylesheet is resolved relative to the page’s Ma The project’s title. If specified, this text is used for the link to the home page in the sidebar, and to complement the titles of the webpages. For instance, a page titled “Sales” in a project titled “ACME, Inc.” will display “Sales | ACME, Inc.” in the browser’s title bar. If not specified, the home page link will appear as “Home” in the sidebar, and page titles will be shown as-is. +## sidebar + +Whether to show the sidebar. Defaults to true if **pages** is not empty. + ## pages An array containing pages and/or sections. If not specified, it defaults to all Markdown files found in the source root in directory listing order. diff --git a/src/config.ts b/src/config.ts index 062459c93..5d80f9895 100644 --- a/src/config.ts +++ b/src/config.ts @@ -36,7 +36,8 @@ export interface Config { output: string; // defaults to dist base: string; // defaults to "/" title?: string; - pages: (Page | Section)[]; // TODO rename to sidebar? + sidebar: boolean; // defaults to true if pages isn’t empty + pages: (Page | Section)[]; pager: boolean; // defaults to true scripts: Script[]; // defaults to empty array head: string; // defaults to empty string @@ -89,6 +90,7 @@ export async function normalizeConfig(spec: any = {}, defaultRoot = "docs"): Pro root = defaultRoot, output = "dist", base = "/", + sidebar, style, theme = "default", deploy, @@ -108,6 +110,7 @@ export async function normalizeConfig(spec: any = {}, defaultRoot = "docs"): Pro let {title, pages = await readPages(root), pager = true, toc = true} = spec; if (title !== undefined) title = String(title); pages = Array.from(pages, normalizePageOrSection); + sidebar = sidebar === undefined ? pages.length > 0 : Boolean(sidebar); pager = Boolean(pager); scripts = Array.from(scripts, normalizeScript); head = String(head); @@ -115,7 +118,7 @@ export async function normalizeConfig(spec: any = {}, defaultRoot = "docs"): Pro footer = String(footer); toc = normalizeToc(toc); deploy = deploy ? {workspace: String(deploy.workspace).replace(/^@+/, ""), project: String(deploy.project)} : null; - return {root, output, base, title, pages, pager, scripts, head, header, footer, toc, style, deploy}; + return {root, output, base, title, sidebar, pages, pager, scripts, head, header, footer, toc, style, deploy}; } function normalizeBase(base: any): string { diff --git a/src/render.ts b/src/render.ts index 30d9c3eeb..190d284ba 100644 --- a/src/render.ts +++ b/src/render.ts @@ -59,6 +59,7 @@ type RenderInternalOptions = async function render(parseResult: ParseResult, options: RenderOptions & RenderInternalOptions): Promise { const {root, base, path, pages, title, preview} = options; + const sidebar = parseResult.data?.sidebar !== undefined ? Boolean(parseResult.data.sidebar) : options.sidebar; const toc = mergeToc(parseResult.data?.toc, options.toc); return String(html` ${path === "/404" ? html`\n` : ""} @@ -89,7 +90,7 @@ import ${preview || parseResult.cells.length > 0 ? `{${preview ? "open, " : ""}d ${ preview ? `\nopen({hash: ${JSON.stringify(parseResult.hash)}, eval: (body) => (0, eval)(body)});\n` : "" }${parseResult.cells.map((cell) => `\n${renderDefineCell(cell)}`).join("")}`)} -${pages.length > 0 ? html`\n${await renderSidebar(title, pages, path)}` : ""}${ +${sidebar ? html`\n${await renderSidebar(title, pages, path)}` : ""}${ toc.show ? html`\n${renderToc(findHeaders(parseResult), toc.label)}` : "" }
${renderHeader(options, parseResult.data)} diff --git a/test/config-test.ts b/test/config-test.ts index be869e4f0..f6adee619 100644 --- a/test/config-test.ts +++ b/test/config-test.ts @@ -11,6 +11,7 @@ describe("readConfig(undefined, root)", () => { output: "dist", base: "/", style: {theme: ["air", "near-midnight"]}, + sidebar: true, pages: [ {path: "/index", name: "Index"}, {path: "/one", name: "One { output: "dist", base: "/", style: {theme: ["air", "near-midnight"]}, + sidebar: true, pages: [{name: "Build test case", path: "/simple"}], title: undefined, toc: {label: "Contents", show: true},