Merge pull request #928 from CrSjimo/master

Fix ghost sidebar when ToC widget is the only widget
pull/954/head
Ruipeng Zhang 2021-09-10 11:00:29 -04:00 committed by GitHub
commit 1e563d6bd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View File

@ -19,15 +19,21 @@ function formatWidgets(widgets) {
return result;
}
function hasColumn(widgets, position) {
function hasColumn(widgets, position, config, page) {
const showToc = (config.toc === true) && ['page', 'post'].includes(page.layout);
if (Array.isArray(widgets)) {
return typeof widgets.find(widget => widget.position === position) !== 'undefined';
return typeof widgets.find(widget => {
if (widget.type === 'toc' && !showToc) {
return false;
}
return widget.position === position;
}) !== 'undefined';
}
return false;
}
function getColumnCount(widgets) {
return [hasColumn(widgets, 'left'), hasColumn(widgets, 'right')].filter(v => !!v).length + 1;
function getColumnCount(widgets, config, page) {
return [hasColumn(widgets, 'left', config, page), hasColumn(widgets, 'right', config, page)].filter(v => !!v).length + 1;
}
function getColumnSizeClass(columnCount) {
@ -61,7 +67,7 @@ class Widgets extends Component {
render() {
const { site, config, helper, page, position } = this.props;
const widgets = formatWidgets(config.widgets)[position] || [];
const columnCount = getColumnCount(config.widgets);
const columnCount = getColumnCount(config.widgets, config, page);
if (!widgets.length) {
return null;
@ -89,7 +95,7 @@ class Widgets extends Component {
}
return null;
})}
{position === 'left' && hasColumn(config.widgets, 'right') ? <div class={classname({
{position === 'left' && hasColumn(config.widgets, 'right', config, page) ? <div class={classname({
'column-right-shadow': true,
'is-hidden-widescreen': true,
'is-sticky': isColumnSticky(config, 'right')

View File

@ -12,7 +12,7 @@ module.exports = class extends Component {
const { site, config, page, helper, body } = this.props;
const language = page.lang || page.language || config.language;
const columnCount = Widgets.getColumnCount(config.widgets);
const columnCount = Widgets.getColumnCount(config.widgets, config, page);
return <html lang={language ? language.substr(0, 2) : ''}>
<Head site={site} config={config} helper={helper} page={page} />