Skip to content

Commit

Permalink
MWPW-136146 Utils Refactoring (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
meganthecoder authored Dec 13, 2023
1 parent 8715918 commit 389fb42
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions blog/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}

Expand Down

0 comments on commit 389fb42

Please sign in to comment.