Skip to content

Commit

Permalink
Merge pull request #182 from yakimka/replace_lazy_images
Browse files Browse the repository at this point in the history
Replace lazy pictures with original ones
  • Loading branch information
ndaidong authored Aug 16, 2021
2 parents 3dee9b7 + 066b5ae commit 9fc5e7c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/utils/parseFromHtml.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ test(`test parseFromHtml a webpage with article but no source`, async () => {
const result = await parseFromHtml(html, ['abcd']);
expect(result).toBeInstanceOf(Object);
});

test(`test parseFromHtml replace src with data-src in img tag`, async () => {
const html = readFileSync('./test-data/html-article-with-data-src.html', 'utf8');
const result = await parseFromHtml(html, ['abcd']);

expect(result.content).toContain('<img src="https://somewhere.any/image1.jpg" />');
expect(result.content).toContain('<img src="https://somewhere.any/image2.jpg" />');
});
2 changes: 1 addition & 1 deletion src/utils/standalizeArticle.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = (htmlArticle, url) => {
});

$('img').each((i, elem) => {
const src = $(elem).attr('src');
const src = $(elem).attr('data-src') || $(elem).attr('src');
if (src) {
$(elem).attr('src', absolutifyUrl(url, src));
}
Expand Down
43 changes: 43 additions & 0 deletions test-data/html-article-with-data-src.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="width=device-width,initial-scale=1" name="viewport">
<meta content="https://somewhere.any/pages/no-article" property="og:url"/>
<title>TechNews</title>
</head>
<body>
<article>
<img data-src="https://somewhere.any/image1.jpg" src="https://somewhere.any/lazy-image.jpg">
<img src="https://somewhere.any/image2.jpg">

Few can name an easygoing deer that isn't a frank hamster. One cannot separate tangerines from
excellent oranges. The literature would have us believe that a dazzling seal is not but a bee?
Some posit the nice strawberry to be less than fair-minded. Washing and polishing the car,a
monkey is the monkey of a turtle;

What we don't know for sure is whether or not the spiders could be said to resemble ambitious
cherries. Of course, a funny zebra's rabbit comes with it the thought that the receptive orange
is a fox. If this was somewhat unclear, a sheep is a strawberry's chimpanzee. The zeitgeist
contends that few can name a kind-hearted grapes that isn't an inventive squirrel! Few can name
a friendly deer that isn't a decorous grapes? What we don't know for sure is whether or not
those flies are nothing more than camels.

It's very tricky, if not impossible, a courageous hippopotamus is a turtle of the mind. Few can
name an affable nectarine that isn't a courteous bird? An alligator is an imaginative fish? Few
can name a quiet blackberry that isn't an independent currant. They were lost without the sedate
fox that composed their puppy; An ant sees a kumquat as a romantic lion. A lemon is a squirrel's
currant.

To be more specific, those turtles are nothing more than fishes. A grape can hardly be
considered a shrewd goldfish without also being an owl. Some unbiased goats are thought of
simply as tangerines.

Shouting with happiness, a courageous elephant is a duck of the mind? Some posit the upbeat
hippopotamus to be less than enchanting. It's an undeniable fact, really; authors often
misinterpret the grape as an endurable rabbit, when in actuality it feels more like a tough
dolphin. We know that a cherry can hardly be considered a responsible apricot without also being
a nectarine.
</article>
</body>
</html>

0 comments on commit 9fc5e7c

Please sign in to comment.