Skip to content

Commit

Permalink
Merge pull request #359 from Netcentric/355-blog-overview-btn-config
Browse files Browse the repository at this point in the history
355 - Configure blog overview
  • Loading branch information
sonaldhekale authored Jul 12, 2023
2 parents c7ab750 + 1d84cb1 commit f4565f8
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions blocks/related-blogs/related-blogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ function buildHeadline(parent, tagConf) {
parent.appendChild(head4);
}

function buildCTASection(parent) {
function buildCTASection(parent, checkBtnLink, count) {
const buttonRow = document.createElement('div');
buttonRow.classList.add('related-button-row');
buttonRow.innerHTML = `<a href="/insights" class="button secondary">${window.placeholders?.default?.blogOverview || 'Blog Overview'}</a>`;
if (checkBtnLink && count > 1) {
buttonRow.innerHTML = `<a href="${checkBtnLink}" class="button secondary">${window.placeholders?.default?.blogOverview || 'Blog Overview'}</a>`;
} else {
buttonRow.innerHTML = `<a href="/insights" class="button secondary">${window.placeholders?.default?.blogOverview || 'Blog Overview'}</a>`;
}
addChevronToButtons(buttonRow);
decorateIcons(buttonRow);
parent.append(buttonRow);
Expand Down Expand Up @@ -45,6 +49,10 @@ async function buildManualRelatedBlogs(block) {
const configuredPaths = [...block.querySelectorAll(':scope > div > div > a')]
.map((anchor) => new URL(anchor.href).pathname);

const count = block.querySelectorAll(':scope > div > div').length;
const blogOverviewBtnRow = block.lastElementChild.children;
const checkBtnLink = blogOverviewBtnRow[0].innerText;

block.innerHTML = ''; // reset

// create container
Expand All @@ -58,7 +66,7 @@ async function buildManualRelatedBlogs(block) {
createCardsList(outerDiv, relatedArticles);

block.append(outerDiv);
buildCTASection(block);
buildCTASection(block, checkBtnLink, count);
}

/**
Expand All @@ -72,7 +80,6 @@ function getVariants(variant) {
auto: buildAutoRelatedBlogs,
manual: defaultVariant,
};

return variants[variant] ?? defaultVariant;
}

Expand Down

0 comments on commit f4565f8

Please sign in to comment.