fix(route/wsj): content glitch (#12127)

* fix(route/wsj): content glitch

* fix(route/wsj): content glitch
This commit is contained in:
Evan
2023-03-17 03:56:54 +08:00
committed by GitHub
parent a0f06e14e6
commit 86d10aefcb
+20 -5
View File
@@ -37,14 +37,29 @@ const parseArticle = (item, ctx) =>
const article = $('article');
item.subTitle = $('h2.sub-head').html();
// Remove h1 and h2
article.find('h1').remove();
article.find('h2').remove();
// Remove podcast
article.find('.media-object-podcast').remove();
// Authors
article.find('.bylineWrap').each((i, e) => {
$(e)
.find('p')
.each(function () {
$(this).replaceWith($(this).html());
});
});
// Images
article.find('.bigTop-hero').each((i, e) => {
// console.log($(e).html());
const imgSrc = $(e).find('amp-img').attr('src');
const imgAlt = $(e).find('amp-img').attr('alt');
const figCaption = $(e).find('.imageCaption').text().trim();
const figCredit = $(e).find('.imageCredit').text().trim();
const fig = $(`<figure><img src="${imgSrc}" alt="${imgAlt}"><figcaption>${figCaption} <span>${figCredit}</span></figcaption></figure>`);
$(fig).insertBefore(e);
$(e).remove();
});
article.find('amp-img').each((i, e) => {
const img = $(`<img width="${e.attribs.width}" height="${e.attribs.height}" src="${e.attribs.src}" alt="${e.attribs.alt}">`);
@@ -61,7 +76,7 @@ const parseArticle = (item, ctx) =>
});
// Remove unwanted DOMs
const unwanted_element_selectors = ['amp-ad', '.wsj-ad'];
const unwanted_element_selectors = ['amp-ad', '.wsj-ad', 'h1', 'h2', '.zonedModule', '.snippet', '.newsletter-inset'];
unwanted_element_selectors.forEach((selector) => {
article.find(selector).each((i, e) => {
$(e).remove();