Skip to content

Commit 84a5622

Browse files
committed
Code readability fixes
mozilla/readability@fc78270
1 parent 3414764 commit 84a5622

File tree

8 files changed

+16
-22
lines changed

8 files changed

+16
-22
lines changed

src/Nodes/NodeTrait.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ trait NodeTrait
3838
* @var array
3939
*/
4040
private $divToPElements = [
41-
'a',
4241
'blockquote',
4342
'dl',
4443
'div',
@@ -47,8 +46,7 @@ trait NodeTrait
4746
'p',
4847
'pre',
4948
'table',
50-
'ul',
51-
'select',
49+
'ul'
5250
];
5351

5452
/**

src/Readability.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -456,19 +456,15 @@ private function getMetadata()
456456
/* @var DOMNode $meta */
457457
$elementName = $meta->getAttribute('name');
458458
$elementProperty = $meta->getAttribute('property');
459-
$content = $meta->getAttribute('content');
459+
$content = $meta->getAttribute('content');
460460
$matches = null;
461461
$name = null;
462462

463463
if ($elementProperty) {
464464
if (preg_match($propertyPattern, $elementProperty, $matches)) {
465-
for ($i = count($matches) - 1; $i >= 0; $i--) {
466-
// Convert to lowercase, and remove any whitespace
467-
// so we can match below.
468-
$name = preg_replace('/\s/', '', mb_strtolower($matches[$i]));
469-
// multiple authors
470-
$values[$name] = trim($content);
471-
}
465+
$name = preg_replace('/\s/', '', mb_strtolower($matches[0]));
466+
// multiple authors
467+
$values[$name] = trim($content);
472468
}
473469
}
474470

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[
2-
"https:\/\/static01.nyt.com\/images\/2017\/01\/14\/world\/13SUDAN-1\/13SUDAN-1-videoSixteenByNineJumbo1600.jpg",
2+
"https:\/\/static01.nyt.com\/images\/2017\/01\/14\/world\/13SUDAN-1\/13SUDAN-1-facebookJumbo.jpg",
33
"https:\/\/static01.nyt.com\/images\/2017\/01\/14\/world\/13SUDAN-1\/13SUDAN-1-master768.jpg"
44
]

test/test-pages/nytimes-1/expected-metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Author": "Jeffrey Gettleman",
33
"Direction": null,
44
"Excerpt": "For the first time since the 1990s, the country will be able to trade extensively with the United States.",
5-
"Image": "https:\/\/static01.nyt.com\/images\/2017\/01\/14\/world\/13SUDAN-1\/13SUDAN-1-videoSixteenByNineJumbo1600.jpg",
5+
"Image": "https:\/\/static01.nyt.com\/images\/2017\/01\/14\/world\/13SUDAN-1\/13SUDAN-1-facebookJumbo.jpg",
66
"Title": "United States to Lift Sudan Sanctions",
77
"SiteName": null
8-
}
8+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[
2-
"https:\/\/static01.nyt.com\/images\/2016\/07\/30\/business\/db-dealprof\/db-dealprof-videoSixteenByNineJumbo1600.jpg",
3-
"https:\/\/static01.nyt.com\/images\/2016\/07\/30\/business\/db-dealprof\/db-dealprof-master315.jpg"
2+
"https:\/\/static01.nyt.com\/images\/2016\/07\/30\/business\/db-dealprof\/db-dealprof-facebookJumbo.jpg",
3+
"https:\/\/static01.nyt.com\/images\/2016\/07\/30\/business\/db-dealprof\/db-dealprof-master315.jpg"
44
]
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"Author": "Steven Davidoff Solomon",
33
"Direction": null,
4-
"Excerpt": "The internet giant’s decision to sell its business is plagued with challenges that reveal how unusual deal structures can affect shareholders.",
5-
"Image": "https:\/\/static01.nyt.com\/images\/2016\/07\/30\/business\/db-dealprof\/db-dealprof-videoSixteenByNineJumbo1600.jpg",
6-
"Title": "Yahoo’s Sale to Verizon Leaves Shareholders With Little Say",
4+
"Excerpt": "The internet giant\u2019s decision to sell its business is plagued with challenges that reveal how unusual deal structures can affect shareholders.",
5+
"Image": "https:\/\/static01.nyt.com\/images\/2016\/07\/30\/business\/db-dealprof\/db-dealprof-facebookJumbo.jpg",
6+
"Title": "Yahoo\u2019s Sale to Verizon Leaves Shareholders With Little Say",
77
"SiteName": null
8-
}
8+
}

test/test-pages/nytimes-3/expected-images.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[
2-
"https:\/\/static01.nyt.com\/images\/2019\/02\/21\/nyregion\/21winterutilities1\/00winterutilities1-videoSixteenByNineJumbo1600.jpg",
2+
"https:\/\/static01.nyt.com\/images\/2019\/02\/21\/nyregion\/21winterutilities1\/00winterutilities1-facebookJumbo.jpg",
33
"https:\/\/static01.nyt.com\/images\/2019\/02\/21\/nyregion\/21winterutilities1\/merlin_150498339_cf9085e5-9756-4169-a5a5-5b516316a3fa-articleLarge.jpg?quality=75&auto=webp&disable=upscale",
44
"https:\/\/static01.nyt.com\/images\/2018\/02\/20\/multimedia\/author-corey-kilgannon\/author-corey-kilgannon-thumbLarge.jpg",
55
"https:\/\/static01.nyt.com\/images\/2019\/02\/21\/nyregion\/21winterutilitiesOAK15\/merlin_56025490_f9412a36-eeb9-4a10-a41e-f324eb7a3248-articleLarge.jpg?quality=75&auto=webp&disable=upscale",

test/test-pages/nytimes-3/expected-metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Author": "By Corey Kilgannon",
33
"Direction": null,
44
"Excerpt": "New York\u2019s aging below-street infrastructure is tough to maintain, and the corrosive rock salt and \u201cfreeze-thaw\u201d cycles of winter make it even worse.",
5-
"Image": "https:\/\/static01.nyt.com\/images\/2019\/02\/21\/nyregion\/21winterutilities1\/00winterutilities1-videoSixteenByNineJumbo1600.jpg",
5+
"Image": "https:\/\/static01.nyt.com\/images\/2019\/02\/21\/nyregion\/21winterutilities1\/00winterutilities1-facebookJumbo.jpg",
66
"Title": "Manhole Fires and Burst Pipes: How Winter Wreaks Havoc on What\u2019s Underneath N.Y.C.",
77
"SiteName": null
88
}

0 commit comments

Comments
 (0)