mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-05-08 01:50:57 +00:00
Merge branch 'create-content-meta-tags' of https://github.com/james-geiger/BookStack into james-geiger-create-content-meta-tags
This commit is contained in:
commit
58fa7679bc
7 changed files with 59 additions and 0 deletions
app/Entities
resources/views
|
@ -138,4 +138,23 @@ class Page extends BookChild
|
||||||
$refreshed->html = (new PageContent($refreshed))->render();
|
$refreshed->html = (new PageContent($refreshed))->render();
|
||||||
return $refreshed;
|
return $refreshed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns URL to a cover image for the page.
|
||||||
|
*/
|
||||||
|
public function getCoverImage()
|
||||||
|
{
|
||||||
|
//$default = $this->book->getBookCover();
|
||||||
|
$default = url('/logo.png');
|
||||||
|
|
||||||
|
$firstImage = (new PageContent($this))->fetchFirstImage();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$cover = $firstImage ? $firstImage : $default;
|
||||||
|
} catch (\Exception $err) {
|
||||||
|
$cover = $default;
|
||||||
|
}
|
||||||
|
return $cover;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -367,4 +367,18 @@ class PageContent
|
||||||
$doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
|
$doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
|
||||||
return $doc;
|
return $doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve first image in page content and return the source URL.
|
||||||
|
*/
|
||||||
|
public function fetchFirstImage()
|
||||||
|
{
|
||||||
|
$htmlContent = $this->page->html;
|
||||||
|
|
||||||
|
$dom = new \DomDocument();
|
||||||
|
$dom->loadHTML($htmlContent);
|
||||||
|
$images = $dom->getElementsByTagName('img');
|
||||||
|
|
||||||
|
return $images->length > 0 ? $images[0]->getAttribute('src') : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,12 @@
|
||||||
<meta name="base-url" content="{{ url('/') }}">
|
<meta name="base-url" content="{{ url('/') }}">
|
||||||
<meta charset="utf-8">
|
<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 -->
|
<!-- Styles and Fonts -->
|
||||||
<link rel="stylesheet" href="{{ versioned_asset('dist/styles.css') }}">
|
<link rel="stylesheet" href="{{ versioned_asset('dist/styles.css') }}">
|
||||||
<link rel="stylesheet" media="print" href="{{ versioned_asset('dist/print-styles.css') }}">
|
<link rel="stylesheet" media="print" href="{{ versioned_asset('dist/print-styles.css') }}">
|
||||||
|
|
|
@ -6,6 +6,11 @@
|
||||||
option:entity-search:entity-type="book"
|
option:entity-search:entity-type="book"
|
||||||
@stop
|
@stop
|
||||||
|
|
||||||
|
@push('social-meta')
|
||||||
|
<meta property="og:description" content="{{ Str::limit($book->description, 100, '...') }}">
|
||||||
|
<meta property="og:image" content="{{ $book->getBookCover() }}">
|
||||||
|
@endpush
|
||||||
|
|
||||||
@section('body')
|
@section('body')
|
||||||
|
|
||||||
<div class="mb-s">
|
<div class="mb-s">
|
||||||
|
|
|
@ -6,6 +6,11 @@
|
||||||
option:entity-search:entity-type="chapter"
|
option:entity-search:entity-type="chapter"
|
||||||
@stop
|
@stop
|
||||||
|
|
||||||
|
@push('social-meta')
|
||||||
|
<meta property="og:description" content="{{ Str::limit($chapter->description, 100) }}">
|
||||||
|
<meta property="og:image" content="{{ $chapter->book->getBookCover() }}">
|
||||||
|
@endpush
|
||||||
|
|
||||||
@section('body')
|
@section('body')
|
||||||
|
|
||||||
<div class="mb-m print-hidden">
|
<div class="mb-m print-hidden">
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
@extends('tri-layout')
|
@extends('tri-layout')
|
||||||
|
|
||||||
|
@push('social-meta')
|
||||||
|
<meta property="og:description" content="{{ Str::limit($page->text, 100, '...') }}">
|
||||||
|
<meta property="og:image" content="{{ $page->getCoverImage() }}">
|
||||||
|
@endpush
|
||||||
|
|
||||||
@section('body')
|
@section('body')
|
||||||
|
|
||||||
<div class="mb-m print-hidden">
|
<div class="mb-m print-hidden">
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
@extends('tri-layout')
|
@extends('tri-layout')
|
||||||
|
|
||||||
|
@push('social-meta')
|
||||||
|
<meta property="og:description" content="{{ Str::limit($shelf->description, 100) }}">
|
||||||
|
<meta property="og:image" content="{{ $shelf->getBookCover() }}">
|
||||||
|
@endpush
|
||||||
|
|
||||||
@section('body')
|
@section('body')
|
||||||
|
|
||||||
<div class="mb-s">
|
<div class="mb-s">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue