Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions layout/common/widgets.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion layout/layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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} />
Expand Down