From 764fa7c53e7679b6c7c20e628a48ab973773ead2 Mon Sep 17 00:00:00 2001 From: Charles Teague Date: Wed, 4 May 2022 09:18:24 -0400 Subject: [PATCH] =?UTF-8?q?if=20the=20left=20sidebar=20is=20empty=20and=20?= =?UTF-8?q?we=E2=80=99re=20in=20full=20layout,=20just=20remove=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit to reproduce, make a page like ``` --- title: The Tech Blog of Charles Teague listing: contents: "blog/**/*.qmd" feed: true categories: true sort: - "date desc" max-description-length: 250 filter-ui: false sort-ui: false type: grid page-layout: full title-block-banner: true margin-header: signup.html toc-location: left --- ``` --- src/format/html/format-html-bootstrap.ts | 45 ++++++++++++++---------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/format/html/format-html-bootstrap.ts b/src/format/html/format-html-bootstrap.ts index b57426afb8..0c0821bb73 100644 --- a/src/format/html/format-html-bootstrap.ts +++ b/src/format/html/format-html-bootstrap.ts @@ -391,6 +391,13 @@ function bootstrapHtmlFinalizer(format: Format, flags: PandocFlags) { const fullLayout = formatHasFullLayout(format); if (fullLayout) { + // If we're in a full layout, get rid of empty sidebar elements + const leftSidebar = hasContents(kSidebarId, doc); + if (!leftSidebar) { + const sidebarEl = doc.getElementById(kSidebarId); + sidebarEl?.remove(); + } + const column = suggestColumn(doc); setMainColumn(doc, column); } @@ -918,28 +925,28 @@ const findOutermostParentElOfType = ( } }; -// Suggests a default column by inspecting sidebars -// if there are none or some, take up the extra space! -function suggestColumn(doc: Document) { - const hasContents = (id: string) => { - const el = doc.getElementById(id); - // Does the element exist - if (el === null) { - return false; - } +const hasContents = (id: string, doc: Document) => { + const el = doc.getElementById(id); + // Does the element exist + if (el === null) { + return false; + } - // Does it have any element children? - if (el.children.length > 0) { - return true; - } + // Does it have any element children? + if (el.children.length > 0) { + return true; + } - // If it doesn't have any element children - // see if there is any text - return !!el.innerText.trim(); - }; + // If it doesn't have any element children + // see if there is any text + return !!el.innerText.trim(); +}; - const leftSidebar = hasContents(kSidebarId); - const rightSidebar = hasContents(kMarginSidebarId); +// Suggests a default column by inspecting sidebars +// if there are none or some, take up the extra space! +function suggestColumn(doc: Document) { + const leftSidebar = hasContents(kSidebarId, doc); + const rightSidebar = hasContents(kMarginSidebarId, doc); const columnClasses = getColumnClasses(doc); const leftContent = [...fullOccludeClz, ...leftOccludeClz].some((clz) => {