in apps-rendering/src/client/article.ts [293:338]
function richLinks(): void {
document
.querySelectorAll('.js-rich-link[data-article-id]')
.forEach((richLink) => {
const articleId = richLink.getAttribute('data-article-id');
if (articleId) {
const options = {
headers: {
Accept: 'application/json',
},
};
void fetch(`${articleId}?richlink`, options)
.then(handleErrors)
.then((resp) => resp.json())
.then((response: unknown) => {
if (isObject(response)) {
const pillar =
typeof response.pillar === 'string'
? response.pillar.toLowerCase()
: null;
const image = response.image;
if (pillar) {
richLink.classList.add(`js-${pillar}`);
}
const placeholder =
richLink.querySelector('.js-image');
if (placeholder && typeof image === 'string') {
const img = document.createElement('img');
img.addEventListener('load', (_) => {
const currentAdSlots = getAdSlots();
void commercialClient.updateAdverts(
currentAdSlots,
);
});
img.setAttribute('alt', 'Related article');
img.setAttribute('src', image);
placeholder.appendChild(img);
}
}
})
.catch((error) => console.error(error));
}
});
}