diff --git a/app/Entities/Models/Page.php b/app/Entities/Models/Page.php
index 076850e63..c244219ea 100644
--- a/app/Entities/Models/Page.php
+++ b/app/Entities/Models/Page.php
@@ -127,17 +127,21 @@ class Page extends BookChild
return $refreshed;
}
+ /**
+ * Returns URL to a cover image for the page.
+ */
public function getCoverImage(): string
{
- $dom = new \DomDocument();
- $dom->loadHTML($this->html);
- $images = $dom->getElementsByTagName('img');
+ $default = $this->book->getBookCover();
+
+ $firstImage = (new PageContent($this))->fetchFirstImage();
try {
- $cover = $images->length > 0 ? $images[0]->getAttribute('src') : $this->book->getBookCover();
- } catch (Exception $err) {
- $cover = $this->book->getBookCover();
+ $cover = $firstImage ? $firstImage : $default;
+ } catch (\Exception $err) {
+ $cover = $default;
}
return $cover;
}
+
}
diff --git a/app/Entities/Tools/PageContent.php b/app/Entities/Tools/PageContent.php
index f60971b8b..e5ea454e7 100644
--- a/app/Entities/Tools/PageContent.php
+++ b/app/Entities/Tools/PageContent.php
@@ -358,4 +358,18 @@ class PageContent
return $html;
}
+
+ /**
+ * Retrieve first image in page content and return the source URL.
+ */
+ public function fetchFirstImage(): string
+ {
+ $htmlContent = $this->page->html;
+
+ $dom = new \DomDocument();
+ $dom->loadHTML($htmlContent);
+ $images = $dom->getElementsByTagName('img');
+
+ return $images[0]->getAttribute('src');
+ }
}
diff --git a/resources/views/base.blade.php b/resources/views/base.blade.php
index e85029573..b7dc83d98 100644
--- a/resources/views/base.blade.php
+++ b/resources/views/base.blade.php
@@ -12,7 +12,6 @@
-
@stack('social-meta')
diff --git a/resources/views/books/show.blade.php b/resources/views/books/show.blade.php
index 72fa9f777..4782da3b9 100644
--- a/resources/views/books/show.blade.php
+++ b/resources/views/books/show.blade.php
@@ -7,7 +7,7 @@
@stop
@push('social-meta')
-
+
@endpush
diff --git a/resources/views/chapters/show.blade.php b/resources/views/chapters/show.blade.php
index 47fd42fe2..32d7943ed 100644
--- a/resources/views/chapters/show.blade.php
+++ b/resources/views/chapters/show.blade.php
@@ -7,7 +7,7 @@
@stop
@push('social-meta')
-
+
@endpush
diff --git a/resources/views/pages/show.blade.php b/resources/views/pages/show.blade.php
index ca639f54b..0810feeb1 100644
--- a/resources/views/pages/show.blade.php
+++ b/resources/views/pages/show.blade.php
@@ -1,8 +1,11 @@
@extends('tri-layout')
@push('social-meta')
-
+
+
+
+ $pageContent->getNavigation($page->html);
@endpush
@section('body')
diff --git a/resources/views/shelves/show.blade.php b/resources/views/shelves/show.blade.php
index 9615466d8..01e9e6629 100644
--- a/resources/views/shelves/show.blade.php
+++ b/resources/views/shelves/show.blade.php
@@ -1,7 +1,7 @@
@extends('tri-layout')
@push('social-meta')
-
+
@endpush