Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MWPW-136146 Utils Refactoring #33

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading