From 389fb42895a0b996b755aeb109674abaf3800c41 Mon Sep 17 00:00:00 2001 From: Megan Thomas Date: Wed, 13 Dec 2023 10:22:31 -0800 Subject: [PATCH] MWPW-136146 Utils Refactoring (#33) --- blog/scripts/utils.js | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/blog/scripts/utils.js b/blog/scripts/utils.js index 2f59ccf..5f0ab42 100644 --- a/blog/scripts/utils.js +++ b/blog/scripts/utils.js @@ -49,16 +49,11 @@ function buildBlock(blockName, content) { const rowEl = document.createElement('div'); row.forEach((col) => { const colEl = document.createElement('div'); - const vals = col.elems || [col]; - vals.forEach((val) => { - if (val) { - if (typeof val === 'string') { - colEl.innerHTML += val; - } else { - colEl.appendChild(val); - } - } - }); + if (typeof col === 'string') { + colEl.innerHTML = col; + } else { + colEl.appendChild(col); + } rowEl.appendChild(colEl); }); blockEl.appendChild(rowEl); @@ -73,15 +68,17 @@ function buildTagsBlock() { const tagsBlock = buildBlock('tags', tagsArray.join(', ')); const main = document.querySelector('main'); const recBlock = main.querySelector('.recommended-articles'); - if (recBlock) { - // Put tags block before recommended articles block - if (recBlock.parentElement.childElementCount === 1) { - recBlock.parentElement.previousElementSibling.append(tagsBlock); - } else { - recBlock.before(tagsBlock); - } - } else { + + if (!recBlock) { main.lastElementChild.append(tagsBlock); + return; + } + + // Put tags block before recommended articles block + if (recBlock.parentElement.childElementCount === 1) { + recBlock.parentElement.previousElementSibling.append(tagsBlock); + } else { + recBlock.before(tagsBlock); } }