Skip to content

Commit 1e563d6

Browse files
authored
Merge pull request #928 from CrSjimo/master
Fix ghost sidebar when ToC widget is the only widget
2 parents 4ae91c1 + 33fd026 commit 1e563d6

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

layout/common/widgets.jsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,21 @@ function formatWidgets(widgets) {
1919
return result;
2020
}
2121

22-
function hasColumn(widgets, position) {
22+
function hasColumn(widgets, position, config, page) {
23+
const showToc = (config.toc === true) && ['page', 'post'].includes(page.layout);
2324
if (Array.isArray(widgets)) {
24-
return typeof widgets.find(widget => widget.position === position) !== 'undefined';
25+
return typeof widgets.find(widget => {
26+
if (widget.type === 'toc' && !showToc) {
27+
return false;
28+
}
29+
return widget.position === position;
30+
}) !== 'undefined';
2531
}
2632
return false;
2733
}
2834

29-
function getColumnCount(widgets) {
30-
return [hasColumn(widgets, 'left'), hasColumn(widgets, 'right')].filter(v => !!v).length + 1;
35+
function getColumnCount(widgets, config, page) {
36+
return [hasColumn(widgets, 'left', config, page), hasColumn(widgets, 'right', config, page)].filter(v => !!v).length + 1;
3137
}
3238

3339
function getColumnSizeClass(columnCount) {
@@ -61,7 +67,7 @@ class Widgets extends Component {
6167
render() {
6268
const { site, config, helper, page, position } = this.props;
6369
const widgets = formatWidgets(config.widgets)[position] || [];
64-
const columnCount = getColumnCount(config.widgets);
70+
const columnCount = getColumnCount(config.widgets, config, page);
6571

6672
if (!widgets.length) {
6773
return null;
@@ -89,7 +95,7 @@ class Widgets extends Component {
8995
}
9096
return null;
9197
})}
92-
{position === 'left' && hasColumn(config.widgets, 'right') ? <div class={classname({
98+
{position === 'left' && hasColumn(config.widgets, 'right', config, page) ? <div class={classname({
9399
'column-right-shadow': true,
94100
'is-hidden-widescreen': true,
95101
'is-sticky': isColumnSticky(config, 'right')

layout/layout.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = class extends Component {
1212
const { site, config, page, helper, body } = this.props;
1313

1414
const language = page.lang || page.language || config.language;
15-
const columnCount = Widgets.getColumnCount(config.widgets);
15+
const columnCount = Widgets.getColumnCount(config.widgets, config, page);
1616

1717
return <html lang={language ? language.substr(0, 2) : ''}>
1818
<Head site={site} config={config} helper={helper} page={page} />

0 commit comments

Comments
 (0)