Skip to content

Commit

Permalink
if the left sidebar is empty and we’re in full layout, just remove it
Browse files Browse the repository at this point in the history
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
---

```
  • Loading branch information
dragonstyle committed May 4, 2022
1 parent a6dab9a commit 764fa7c
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions src/format/html/format-html-bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 764fa7c

Please sign in to comment.