diff --git a/src/BookProvider.php b/src/BookProvider.php index c240677a..7b6dca1b 100644 --- a/src/BookProvider.php +++ b/src/BookProvider.php @@ -169,17 +169,6 @@ public function getMetadata( string $title, bool $isMetadata, DOMDocument $doc ) $pictures = $this->getPicturesData( $pictures ); } - // Clean up the image URLs if they're protocol relative or only a path. This would probably be better in - // PageParser, but it doesn't have access to the domain name. - foreach ( $pictures as $pic ) { - $url = $pic->url; - if ( str_starts_with( $url, '//' ) ) { - $url = 'https:' . $url; - } elseif ( str_starts_with( $url, '/' ) ) { - $url = 'https://' . $this->api->getDomainName() . $url; - } - $pic->url = $url; - } $book->pictures = $pictures; return $book; @@ -226,6 +215,14 @@ protected function getPicturesData( array $pictures ) { $requests = function () use ( $client, $pictures ) { foreach ( $pictures as $picture ) { $url = $picture->url; + // Clean up the image URLs if they're protocol relative or only a path. This would probably be better in + // PageParser, but it doesn't have access to the domain name. + if ( str_starts_with( $url, '//' ) ) { + $url = 'https:' . $url; + } elseif ( str_starts_with( $url, '/' ) ) { + $url = 'https://' . $this->api->getDomainName() . $url; + } + $picture->url = $url; yield function () use ( $client, $url ) { // We could use the 'sink' option here, but for https://github.com/Kevinrob/guzzle-cache-middleware/issues/82 // @phan-suppress-next-line PhanUndeclaredMethod Magic method not declared in the interface diff --git a/tests/Cli/BookCliTest.php b/tests/Cli/BookCliTest.php index e8758674..6845ccc6 100644 --- a/tests/Cli/BookCliTest.php +++ b/tests/Cli/BookCliTest.php @@ -12,7 +12,8 @@ class BookCliTest extends TestCase { public function bookProvider() { return [ [ 'The_Kiss_and_its_History', 'en' ], - [ 'Les_Fleurs_du_mal', 'fr' ] + [ 'Les_Fleurs_du_mal', 'fr' ], + [ 'Stelae_of_Naukratis', 'mul' ], ]; }