Skip to content

Commit b285d89

Browse files
committed
Use final URI host when getting relative images as cover.
It fixes #12, mainly done for google.com pages.
1 parent 0c1bbff commit b285d89

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/Parsers/HtmlParser.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use Dusterio\LinkPreview\Readers\HttpReader;
1212
use Dusterio\LinkPreview\Models\HtmlPreview;
1313
use Symfony\Component\DomCrawler\Crawler;
14+
use GuzzleHttp\Psr7\Uri;
15+
use GuzzleHttp\Psr7\UriResolver;
1416

1517
/**
1618
* Class HtmlParser
@@ -180,6 +182,11 @@ protected function parseHtml(LinkInterface $link)
180182

181183
if (!isset($cover) && count($images)) $cover = $images[0];
182184

185+
$coverUri = new Uri($cover);
186+
if (!Uri::isAbsolute($coverUri)) {
187+
$cover = (string) UriResolver::resolve($link->getEffectiveUrl(), $coverUri);
188+
}
189+
183190
return compact('cover', 'title', 'description', 'images', 'video', 'videoType');
184191
}
185192
}

0 commit comments

Comments
 (0)