mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-23 16:03:58 +08:00
Create Open Graph meta tags for book/page/chapter/shelf
This commit is contained in:
parent
4b36df08a8
commit
e458411f91
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,13 @@
|
|||
<meta name="base-url" content="{{ url('/') }}">
|
||||
<meta charset="utf-8">
|
||||
|
||||
<!-- Social Cards Meta -->
|
||||
|
||||
<meta property="og:title" content="{{ isset($pageTitle) ? $pageTitle . ' | ' : '' }}{{ setting('app-name') }}">
|
||||
<meta property="og:url" content="{{ url()->current() }}">
|
||||
@stack('social-meta')
|
||||
|
||||
|
||||
<!-- Styles and Fonts -->
|
||||
<link rel="stylesheet" href="{{ versioned_asset('dist/styles.css') }}">
|
||||
<link rel="stylesheet" media="print" href="{{ versioned_asset('dist/print-styles.css') }}">
|
||||
|
|
|
@ -6,6 +6,11 @@
|
|||
option:entity-search:entity-type="book"
|
||||
@stop
|
||||
|
||||
@push('social-meta')
|
||||
<meta property="og:description" content="{{ Str::words($book->description, 50, '...') }}">
|
||||
<meta property="og:image" content="{{ $book->getBookCover() }}">
|
||||
@endpush
|
||||
|
||||
@section('body')
|
||||
|
||||
<div class="mb-s">
|
||||
|
|
|
@ -6,6 +6,11 @@
|
|||
option:entity-search:entity-type="chapter"
|
||||
@stop
|
||||
|
||||
@push('social-meta')
|
||||
<meta property="og:description" content="{{ Str::words($chapter->description, 50, '...') }}">
|
||||
<meta property="og:image" content="{{ $chapter->book->getBookCover() }}">
|
||||
@endpush
|
||||
|
||||
@section('body')
|
||||
|
||||
<div class="mb-m print-hidden">
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
@extends('tri-layout')
|
||||
|
||||
@push('social-meta')
|
||||
<meta property="og:description" content="{{ Str::words($page->html, 50, '...') }}">
|
||||
<meta property="og:image" content="{{ $page->getCoverImage() }}">
|
||||
@endpush
|
||||
|
||||
@section('body')
|
||||
|
||||
<div class="mb-m print-hidden">
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
@extends('tri-layout')
|
||||
|
||||
@push('social-meta')
|
||||
<meta property="og:description" content="{{ Str::words($shelf->description, 50, '...') }}">
|
||||
<meta property="og:image" content="{{ $shelf->getBookCover() }}">
|
||||
@endpush
|
||||
|
||||
@section('body')
|
||||
|
||||
<div class="mb-s">
|
||||
|
|
Loading…
Reference in New Issue
Block a user