Skip to content

Commit

Permalink
fix(route/wsj): content glitch (DIYgod#12127)
Browse files Browse the repository at this point in the history
* fix(route/wsj): content glitch

* fix(route/wsj): content glitch
  • Loading branch information
EthanWng97 authored Mar 16, 2023
1 parent a0f06e1 commit 86d10ae
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions lib/v2/wsj/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}">`);

Expand All @@ -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();
Expand Down

0 comments on commit 86d10ae

Please sign in to comment.