From 131d923d38ba9a2420cd9d0d8cf7eb1c35ff6a50 Mon Sep 17 00:00:00 2001 From: Evan Tseng Date: Fri, 7 Oct 2016 18:22:05 +0800 Subject: [PATCH] Bug 1167568 - Find a better topCandidate if there are other nodes scores are high enough, r=Gijs --- .travis.yml | 2 +- Readability.js | 35 +- test/test-pages/ehow-1/expected.html | 21 - test/test-pages/ehow-2/expected-metadata.json | 6 + test/test-pages/ehow-2/expected.html | 164 ++ test/test-pages/ehow-2/source.html | 1621 +++++++++++++++++ 6 files changed, 1825 insertions(+), 24 deletions(-) create mode 100644 test/test-pages/ehow-2/expected-metadata.json create mode 100644 test/test-pages/ehow-2/expected.html create mode 100644 test/test-pages/ehow-2/source.html diff --git a/.travis.yml b/.travis.yml index 11d7ff7..dacc49c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js sudo: false node_js: - - '5.3' + - '6.0' script: - npm run lint - npm run test diff --git a/Readability.js b/Readability.js index 4501943..7749a3a 100644 --- a/Readability.js +++ b/Readability.js @@ -112,7 +112,7 @@ Readability.prototype = { // All of the regular expressions in use within readability. // Defined up here so we don't instantiate them repeatedly in loops. REGEXPS: { - unlikelyCandidates: /banner|combx|comment|community|cover-wrap|disqus|extra|foot|header|legends|menu|modal|related|remark|rss|shoutbox|sidebar|skyscraper|sponsor|ad-break|agegate|pagination|pager|popup|yom-remote/i, + unlikelyCandidates: /banner|breadcrumbs|combx|comment|community|cover-wrap|disqus|extra|foot|header|legends|menu|modal|related|remark|replies|rss|shoutbox|sidebar|skyscraper|social|sponsor|ad-break|agegate|pagination|pager|popup|yom-remote/i, okMaybeItsACandidate: /and|article|body|column|main|shadow/i, positive: /article|body|content|entry|hentry|h-entry|main|page|pagination|post|text|blog|story/i, negative: /hidden|^hid$| hid$| hid |^hid |banner|combx|comment|com-|contact|foot|footer|footnote|masthead|media|meta|modal|outbrain|promo|related|scroll|share|shoutbox|sidebar|skyscraper|sponsor|shopping|tags|tool|widget/i, @@ -844,6 +844,33 @@ Readability.prototype = { this._initializeNode(topCandidate); } else if (topCandidate) { + // Find a better top candidate node if it contains (at least three) nodes which belong to `topCandidates` array + // and whose scores are quite closed with current `topCandidate` node. + var alternativeCandidateAncestors = []; + for (var i = 1; i < topCandidates.length; i++) { + if (topCandidates[i].readability.contentScore / topCandidate.readability.contentScore >= 0.75) { + alternativeCandidateAncestors.push(this._getNodeAncestors(topCandidates[i])); + } + } + var MINIMUM_TOPCANDIDATES = 3; + if (alternativeCandidateAncestors.length >= MINIMUM_TOPCANDIDATES) { + parentOfTopCandidate = topCandidate.parentNode; + while (parentOfTopCandidate.tagName !== "BODY") { + var listsContainingThisAncestor = 0; + for (var ancestorIndex = 0; ancestorIndex < alternativeCandidateAncestors.length && listsContainingThisAncestor < MINIMUM_TOPCANDIDATES; ancestorIndex++) { + listsContainingThisAncestor += Number(alternativeCandidateAncestors[ancestorIndex].includes(parentOfTopCandidate)); + } + if (listsContainingThisAncestor >= MINIMUM_TOPCANDIDATES) { + topCandidate = parentOfTopCandidate; + break; + } + parentOfTopCandidate = parentOfTopCandidate.parentNode; + } + } + if (!topCandidate.readability) { + this._initializeNode(topCandidate); + } + // Because of our bonus system, parents of candidates might have scores // themselves. They get half of the node. There won't be nodes with higher // scores than our topCandidate, but if we see the score going *up* in the first @@ -855,7 +882,11 @@ Readability.prototype = { var lastScore = topCandidate.readability.contentScore; // The scores shouldn't get too low. var scoreThreshold = lastScore / 3; - while (parentOfTopCandidate && parentOfTopCandidate.readability) { + while (parentOfTopCandidate.tagName !== "BODY") { + if (!parentOfTopCandidate.readability) { + parentOfTopCandidate = parentOfTopCandidate.parentNode; + continue; + } var parentScore = parentOfTopCandidate.readability.contentScore; if (parentScore < scoreThreshold) break; diff --git a/test/test-pages/ehow-1/expected.html b/test/test-pages/ehow-1/expected.html index 2e68c52..596867f 100644 --- a/test/test-pages/ehow-1/expected.html +++ b/test/test-pages/ehow-1/expected.html @@ -116,27 +116,6 @@
Cloche terrarium (Lucy Akins)
- -
\ No newline at end of file diff --git a/test/test-pages/ehow-2/expected-metadata.json b/test/test-pages/ehow-2/expected-metadata.json new file mode 100644 index 0000000..68b0560 --- /dev/null +++ b/test/test-pages/ehow-2/expected-metadata.json @@ -0,0 +1,6 @@ +{ + "title": "How to Throw a Graduation Party on a Budget (with Pictures)", + "byline": "Gina Roberts-Grey", + "excerpt": "How to Throw a Graduation Party on a Budget. Graduation parties are a great way to commemorate the years of hard work teens and college co-eds devote to education. They’re also costly for mom and dad.The average cost of a graduation party in 2013 was a whopping $1,200, according to Graduationparty.com; $700 of that was allocated for food....", + "readerable": true +} diff --git a/test/test-pages/ehow-2/expected.html b/test/test-pages/ehow-2/expected.html new file mode 100644 index 0000000..c4ecc35 --- /dev/null +++ b/test/test-pages/ehow-2/expected.html @@ -0,0 +1,164 @@ +
+
+
+
+ + + +
+
+ +
+
+
+
+
+

Graduation parties are a great way to commemorate the years of hard work teens and college co-eds devote to education. They’re also costly for mom and dad.

+

The average cost of a graduation party in 2013 was a whopping $1,200, according to Graduationparty.com; $700 of that was allocated for food. However that budget was based on Midwestern statistics, and parties in urban areas like New York City are thought to have a much higher price tag.

+

Thankfully, there are plenty of creative ways to trim a little grad party fat without sacrificing any of the fun or celebratory spirit.

+
+
+ Graduation +
+
+ (Mike Watson Images/Moodboard/Getty) +
+
+
+ + + + +

Parties hosted at restaurants, clubhouses and country clubs eliminate the need to spend hours cleaning up once party guests have gone home. But that convenience comes with a price tag. A country club may charge as much as $2,000 for room rental and restaurant food and beverage will almost always cost more than food prepped and served at home.

+
+ Save money hosting the party at home. +
+
+ Thomas Jackson/Digital Vision/Getty Images
+
+
+
+
+ + +

Instead of hiring a DJ, use your iPod or Smartphone to spin the tunes. Both easily hook up to most speakers or mp3 compatible docks to play music from your music library. Or download Pandora, the free online radio app, and play hours of music for free.

+

Personalize the music with a playlist of the grad’s favorite songs or songs that were big hits during his or her years in school.

+
+ Online radio can take the place of a hired DJ. +
+
+ Spencer Platt/Getty Images News/Getty Images
+
+
+
+
+ + +

Avoid canned drinks, which guests often open, but don't finish. Serve pitchers of tap water with lemon and cucumber slices or sliced strawberries for an interesting and refreshing flavor. Opt for punches and non-alcoholic drinks for high school graduates that allow guests to dole out the exact amount they want to drink.

+
+ Serve drinks in pitchers, not in cans. +
+
+ evgenyb/iStock/Getty Images
+
+
+ +
+
+ + +

Instead of inviting everyone you – and the graduate – know or ever knew, scale back the guest list. Forgo inviting guests that you or your grad haven't seen for eons. There is no reason to provide provisions for people who are essentially out of your lives. Sticking to a small, but personal, guest list allows more time to mingle with loved ones during the party, too.

+
+ Limit guests to those close to the graduate. +
+
+ Kane Skennar/Photodisc/Getty Images
+
+
+
+
+ + +

See if your grad and his best friend, girlfriend or close family member would consider hosting a joint party. You can split some of the expenses, especially when the two graduates share mutual friends. You'll also have another parent to bounce ideas off of and to help you stick to your budget when you're tempted to splurge.

+
+ Throw a joint bash for big savings. +
+
+ Mike Watson Images/Moodboard/Getty
+
+
+
+
+ + +

Skip carving stations of prime rib and jumbo shrimp as appetizers, especially for high school graduation parties. Instead, serve some of the graduate's favorite side dishes that are cost effective, like a big pot of spaghetti with breadsticks. Opt for easy and simple food such as pizza, finger food and mini appetizers.

+

Avoid pre-packaged foods and pre-made deli platters. These can be quite costly. Instead, make your own cheese and deli platters for less than half the cost of pre-made.

+
+ Cost effective appetizers are just as satisfying as pre-made deli platters. +
+
+ Mark Stout/iStock/Getty Images
+
+
+
+
+ + +

Instead of an evening dinner party, host a grad lunch or all appetizers party. Brunch and lunch fare or finger food costs less than dinner. Guests also tend to consume less alcohol in the middle of the day, which keeps cost down.

+
+ A brunch gathering will cost less than a dinner party. +
+
+ Mark Stout/iStock/Getty Images
+
+
+ + +
+
+ + +

Decorate your party in the graduate's current school colors or the colors of the school he or she will be headed to next. Décor that is not specifically graduation-themed may cost a bit less, and any leftovers can be re-used for future parties, picnics and events.

+
+ Theme the party by color without graduation-specific decor. +
+
+ jethuynh/iStock/Getty Images
+
+
+
+
+ + +

+ Related Searches +

+ + +

Promoted By Zergnet

+ +
+
+ + +
+
diff --git a/test/test-pages/ehow-2/source.html b/test/test-pages/ehow-2/source.html new file mode 100644 index 0000000..6976de3 --- /dev/null +++ b/test/test-pages/ehow-2/source.html @@ -0,0 +1,1621 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + How to Throw a Graduation Party on a Budget (with Pictures) | eHow + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+ +
+ +
+
+
+ +
+ +
+
+ + +
+

+ How to Throw a Graduation Party on a Budget

+
+ + + +
+
+
+ + +
+
+ Save +
+
+ + + +
+
+
+
+ +
+
+
+
+
+

Graduation parties are a great way to commemorate the years of hard work teens and college co-eds devote to education. They’re also costly for mom and dad.

+

The average cost of a graduation party in 2013 was a whopping $1,200, according to Graduationparty.com; $700 of that was allocated for food. However that budget was based on Midwestern statistics, and parties in urban areas like New York City are thought to have a much higher price tag.

+

Thankfully, there are plenty of creative ways to trim a little grad party fat without sacrificing any of the fun or celebratory spirit.

+
+
+ Graduation +
+
+ (Mike Watson Images/Moodboard/Getty) +
+
+
+ +
+ +
+ + +
+
+
+

Parties hosted at restaurants, clubhouses and country clubs eliminate the need to spend hours cleaning up once party guests have gone home. But that convenience comes with a price tag. A country club may charge as much as $2,000 for room rental and restaurant food and beverage will almost always cost more than food prepped and served at home.

+
+ Save money hosting the party at home. +
+
+ Thomas Jackson/Digital Vision/Getty Images
+
+
+
+
+ + +
+
+
+

Instead of hiring a DJ, use your iPod or Smartphone to spin the tunes. Both easily hook up to most speakers or mp3 compatible docks to play music from your music library. Or download Pandora, the free online radio app, and play hours of music for free.

+

Personalize the music with a playlist of the grad’s favorite songs or songs that were big hits during his or her years in school.

+
+ Online radio can take the place of a hired DJ. +
+
+ Spencer Platt/Getty Images News/Getty Images
+
+
+
+
+ + +
+
+
+

Avoid canned drinks, which guests often open, but don't finish. Serve pitchers of tap water with lemon and cucumber slices or sliced strawberries for an interesting and refreshing flavor. Opt for punches and non-alcoholic drinks for high school graduates that allow guests to dole out the exact amount they want to drink.

+
+ Serve drinks in pitchers, not in cans. +
+
+ evgenyb/iStock/Getty Images
+
+
+
+
+
+ +
+
+
+
+ + +
+
+
+

Instead of inviting everyone you – and the graduate – know or ever knew, scale back the guest list. Forgo inviting guests that you or your grad haven't seen for eons. There is no reason to provide provisions for people who are essentially out of your lives. Sticking to a small, but personal, guest list allows more time to mingle with loved ones during the party, too.

+
+ Limit guests to those close to the graduate. +
+
+ Kane Skennar/Photodisc/Getty Images
+
+
+
+
+ + +
+
+
+

See if your grad and his best friend, girlfriend or close family member would consider hosting a joint party. You can split some of the expenses, especially when the two graduates share mutual friends. You'll also have another parent to bounce ideas off of and to help you stick to your budget when you're tempted to splurge.

+
+ Throw a joint bash for big savings. +
+
+ Mike Watson Images/Moodboard/Getty
+
+
+
+
+ + +
+
+
+

Skip carving stations of prime rib and jumbo shrimp as appetizers, especially for high school graduation parties. Instead, serve some of the graduate's favorite side dishes that are cost effective, like a big pot of spaghetti with breadsticks. Opt for easy and simple food such as pizza, finger food and mini appetizers.

+

Avoid pre-packaged foods and pre-made deli platters. These can be quite costly. Instead, make your own cheese and deli platters for less than half the cost of pre-made.

+
+ Cost effective appetizers are just as satisfying as pre-made deli platters. +
+
+ Mark Stout/iStock/Getty Images
+
+
+
+
+ + +
+
+
+

Instead of an evening dinner party, host a grad lunch or all appetizers party. Brunch and lunch fare or finger food costs less than dinner. Guests also tend to consume less alcohol in the middle of the day, which keeps cost down.

+
+ A brunch gathering will cost less than a dinner party. +
+
+ Mark Stout/iStock/Getty Images
+
+
+ +
+
+
+ + +
+
+
+

Decorate your party in the graduate's current school colors or the colors of the school he or she will be headed to next. Décor that is not specifically graduation-themed may cost a bit less, and any leftovers can be re-used for future parties, picnics and events.

+
+ Theme the party by color without graduation-specific decor. +
+
+ jethuynh/iStock/Getty Images
+
+
+
+
+
+
+
+ +
+

+ Related Searches +

+
+
+
+
+
Promoted By Zergnet
+
+

Comments

+
+ + +
+
+
+ +
+ +
+ +
+ +

+ Related Searches +

+
+
+
+
+ + +Check It Out + + +

+ 13 Delicious Thanksgiving Sides That'll Make Turkey Insignificant

+
+
+ + +
+ +
+
+
+
+ +
+
M
+
+
Is DIY in your DNA? Become part of our maker community.
+ Submit Your Work! +
+
+ + +
+ + + +
+ + + + + + + + + + + + + + + +
+ + + + + + + + \ No newline at end of file