add a judgement of the existence of toc
parent
4ae91c1d1e
commit
81fa904599
|
@ -19,15 +19,19 @@ function formatWidgets(widgets) {
|
||||||
return result;
|
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)) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getColumnCount(widgets) {
|
function getColumnCount(widgets, config, page) {
|
||||||
return [hasColumn(widgets, 'left'), hasColumn(widgets, 'right')].filter(v => !!v).length + 1;
|
return [hasColumn(widgets, 'left', config, page), hasColumn(widgets, 'right', config, page)].filter(v => !!v).length + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getColumnSizeClass(columnCount) {
|
function getColumnSizeClass(columnCount) {
|
||||||
|
@ -61,7 +65,7 @@ class Widgets extends Component {
|
||||||
render() {
|
render() {
|
||||||
const { site, config, helper, page, position } = this.props;
|
const { site, config, helper, page, position } = this.props;
|
||||||
const widgets = formatWidgets(config.widgets)[position] || [];
|
const widgets = formatWidgets(config.widgets)[position] || [];
|
||||||
const columnCount = getColumnCount(config.widgets);
|
const columnCount = getColumnCount(config.widgets, config, page);
|
||||||
|
|
||||||
if (!widgets.length) {
|
if (!widgets.length) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -89,7 +93,7 @@ class Widgets extends Component {
|
||||||
}
|
}
|
||||||
return null;
|
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,
|
'column-right-shadow': true,
|
||||||
'is-hidden-widescreen': true,
|
'is-hidden-widescreen': true,
|
||||||
'is-sticky': isColumnSticky(config, 'right')
|
'is-sticky': isColumnSticky(config, 'right')
|
||||||
|
|
|
@ -12,7 +12,7 @@ module.exports = class extends Component {
|
||||||
const { site, config, page, helper, body } = this.props;
|
const { site, config, page, helper, body } = this.props;
|
||||||
|
|
||||||
const language = page.lang || page.language || config.language;
|
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) : ''}>
|
return <html lang={language ? language.substr(0, 2) : ''}>
|
||||||
<Head site={site} config={config} helper={helper} page={page} />
|
<Head site={site} config={config} helper={helper} page={page} />
|
||||||
|
|
Loading…
Reference in New Issue