1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-31 15:24:31 +03:00

Create Open Graph meta tags for book/page/chapter/shelf

This commit is contained in:
James Geiger
2020-12-21 23:20:13 -06:00
parent 4b36df08a8
commit e458411f91
6 changed files with 41 additions and 0 deletions

View File

@ -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;
}
}