Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContentExtractor: remove logic for wp img lazy loading #251

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/Extractor/ContentExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -593,20 +593,6 @@ function ($element, $currentEntity) {
continue;
}

// Custom case for WordPress plugin http://wordpress.org/extend/plugins/lazy-load/
// the plugin replaces the src attribute to point to a 1x1 gif and puts the original src
// inside the data-lazy-src attribute. It also places the original image inside a noscript element
// next to the amended one.
// @see https://plugins.trac.wordpress.org/browser/lazy-load/trunk/lazy-load.php
if (null !== $e->nextSibling && 'noscript' === $e->nextSibling->nodeName) {
$newElem = $e->ownerDocument->createDocumentFragment();
$newElem->appendXML($e->nextSibling->innerHTML);
$e->nextSibling->parentNode->replaceChild($newElem, $e->nextSibling);
$e->parentNode->removeChild($e);

continue;
}

$attributes = [];
foreach ($this->config['src_lazy_load_attributes'] as $attribute) {
if ($e->hasAttribute($attribute)) {
Expand Down
13 changes: 13 additions & 0 deletions tests/GrabyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,19 @@ public function testWithTooLongHtmlJitFail(): void
$this->assertNotSame('No title found', $res['title']);
}

public function testImgLazyLoading(): void
{
$graby = $this->getGrabyWithMock('/fixtures/content/uxmovement-img-lazy.html');
$res = $graby->fetchContent('https://uxmovement.com/buttons/dont-use-inverted-color-cues-on-toggle-buttons/');

$doc = new \DOMDocument();
$doc->loadXML('<html><body>' . $res['html'] . '</body></html>');

/** @var \DOMElement */
$item = $doc->getElementsByTagName('img')->item(0);
$this->assertStringContainsString('https://uxmovement.com/wp-content/uploads/2021/01/icc-equalcontrastratio.png', $item->getAttribute('src'));
}

/**
* Return an instance of graby with a mocked Guzzle client returning data from a predefined file.
*/
Expand Down
Loading