From 0c3b8904b809d522c2aaf29d6bca40071c99baad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 19 Jan 2023 22:01:56 -0500 Subject: [PATCH] fix: don't render empty widgets --- public/src/widgets.js | 9 +++++---- src/widgets/index.js | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/public/src/widgets.js b/public/src/widgets.js index 494546c023..de2d0e8697 100644 --- a/public/src/widgets.js +++ b/public/src/widgets.js @@ -9,17 +9,18 @@ module.exports.render = function (template) { locations.forEach(function (location) { let area = $('#content [widget-area="' + location + '"],#content [data-widget-area="' + location + '"]').eq(0); - if (area.length) { + const widgetsAtLocation = ajaxify.data.widgets[location] || []; + if (area.length || !widgetsAtLocation.length) { return; } - const widgetsAtLocation = ajaxify.data.widgets[location] || []; let html = ''; - widgetsAtLocation.forEach(function (widget) { html += widget.html; }); - + if (!html) { + return; + } if (location === 'footer' && !$('#content [widget-area="footer"],#content [data-widget-area="footer"]').length) { $('#content').append($('
')); } else if (location === 'sidebar' && !$('#content [widget-area="sidebar"],#content [data-widget-area="sidebar"]').length) { diff --git a/src/widgets/index.js b/src/widgets/index.js index 473a33a820..03b765740a 100644 --- a/src/widgets/index.js +++ b/src/widgets/index.js @@ -27,7 +27,7 @@ widgets.render = async function (uid, options) { const returnData = {}; locations.forEach((location, i) => { if (Array.isArray(widgetData[i]) && widgetData[i].length) { - returnData[location] = widgetData[i].filter(Boolean); + returnData[location] = widgetData[i].filter(widget => widget && widget.html); } });