From 81fa9045998eb9c58f255b5f8d8d85e7aa2674c1 Mon Sep 17 00:00:00 2001 From: CrSjimo Date: Sun, 5 Sep 2021 21:11:26 +0800 Subject: [PATCH 1/2] add a judgement of the existence of toc --- layout/common/widgets.jsx | 16 ++++++++++------ layout/layout.jsx | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/layout/common/widgets.jsx b/layout/common/widgets.jsx index 0a69ca7..e89dc4c 100644 --- a/layout/common/widgets.jsx +++ b/layout/common/widgets.jsx @@ -19,15 +19,19 @@ function formatWidgets(widgets) { return result; } -function hasColumn(widgets, position) { +function hasColumn(widgets, position, config, page) { + const showToc = (config.toc === true || page.toc) && ['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 +65,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 +93,7 @@ class Widgets extends Component { } return null; })} - {position === 'left' && hasColumn(config.widgets, 'right') ?
From 33fd026148fdee59c5f6abd7d1baa4568b43f8dc Mon Sep 17 00:00:00 2001 From: CrSjimo Date: Fri, 10 Sep 2021 22:20:50 +0800 Subject: [PATCH 2/2] small adjustments --- layout/common/widgets.jsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/layout/common/widgets.jsx b/layout/common/widgets.jsx index e89dc4c..a8f4688 100644 --- a/layout/common/widgets.jsx +++ b/layout/common/widgets.jsx @@ -20,11 +20,13 @@ function formatWidgets(widgets) { } function hasColumn(widgets, position, config, page) { - const showToc = (config.toc === true || page.toc) && ['page', 'post'].includes(page.layout); + const showToc = (config.toc === true) && ['page', 'post'].includes(page.layout); if (Array.isArray(widgets)) { return typeof widgets.find(widget => { - if(widget.type === 'toc' && !showToc)return false; - return widget.position === position + if (widget.type === 'toc' && !showToc) { + return false; + } + return widget.position === position; }) !== 'undefined'; } return false;