diff --git a/app/Entities/Models/Page.php b/app/Entities/Models/Page.php index 52c64f048..076850e63 100644 --- a/app/Entities/Models/Page.php +++ b/app/Entities/Models/Page.php @@ -126,4 +126,18 @@ class Page extends BookChild $refreshed->html = (new PageContent($refreshed))->render(); return $refreshed; } + + public function getCoverImage(): string + { + $dom = new \DomDocument(); + $dom->loadHTML($this->html); + $images = $dom->getElementsByTagName('img'); + + try { + $cover = $images->length > 0 ? $images[0]->getAttribute('src') : $this->book->getBookCover(); + } catch (Exception $err) { + $cover = $this->book->getBookCover(); + } + return $cover; + } } diff --git a/resources/views/base.blade.php b/resources/views/base.blade.php index a5404a365..e85029573 100644 --- a/resources/views/base.blade.php +++ b/resources/views/base.blade.php @@ -11,6 +11,13 @@ + + + + + @stack('social-meta') + + diff --git a/resources/views/books/show.blade.php b/resources/views/books/show.blade.php index def198bdd..72fa9f777 100644 --- a/resources/views/books/show.blade.php +++ b/resources/views/books/show.blade.php @@ -6,6 +6,11 @@ option:entity-search:entity-type="book" @stop +@push('social-meta') + + +@endpush + @section('body')