functionformatWidgets(widgets, page) { const result = {}; if (Array.isArray(widgets)) { widgets.filter(widget =>typeof widget === 'object').forEach(widget => { // Decide the widget should show in the page or not if ('pages'in widget && typeof widget.pages === 'object') { const pageName = getPageName(page); var pageShow = false; widget.pages.forEach(item => { if (item === pageName) { pageShow = true; } }); if (!pageShow) { return; } } // Just left or right should the widget show in if ('position'in widget && (widget.position === 'left' || widget.position === 'right')) { if (!(widget.positionin result)) { result[widget.position] = [widget]; } else { result[widget.position].push(widget); } } }); } return result; }
widgets: # Profile widget configurations - # Where should the widget be placed, left sidebar or right sidebar position:left type:profile # ... # Specified pages that will show the widget, all pages by default. eg: index, archive, category, tag, post pages: -index # ... # Table of contents widget configurations - # Where should the widget be placed, left sidebar or right sidebar position:right type:toc pages: -post # Recent posts widget configurations - # Where should the widget be placed, left sidebar or right sidebar position:right type:recent_posts # Categories widget configurations - # Where should the widget be placed, left sidebar or right sidebar position:right type:categories # Tags widget configurations - # Where should the widget be placed, left sidebar or right sidebar position:right type:tags