From 3df53c74119b1b3a345983fa9e146d1fe4a789d0 Mon Sep 17 00:00:00 2001 From: Louis Jeckel Date: Mon, 14 Sep 2020 10:50:27 +0200 Subject: [PATCH] add meta social articel --- .../Controllers/SocialArticleController.php | 1 + app/Models/HasMetaTags.php | 42 +++++++++++++++++++ app/Models/LaboArticle.php | 2 + app/Models/SocialArticle.php | 13 +++++- .../views/admin/socialArticles/form.blade.php | 6 +++ resources/views/layouts/app.blade.php | 15 +++++++ 6 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 app/Models/HasMetaTags.php diff --git a/app/Http/Controllers/SocialArticleController.php b/app/Http/Controllers/SocialArticleController.php index 75bfdd3..7b72546 100644 --- a/app/Http/Controllers/SocialArticleController.php +++ b/app/Http/Controllers/SocialArticleController.php @@ -22,6 +22,7 @@ class SocialArticleController extends Controller \View::share('article', $article); \View::share('title', $article->title); + \View::share('meta', $article->getMetaData()); return view('social-articles.show'); } diff --git a/app/Models/HasMetaTags.php b/app/Models/HasMetaTags.php new file mode 100644 index 0000000..c8912ad --- /dev/null +++ b/app/Models/HasMetaTags.php @@ -0,0 +1,42 @@ + $this->getMetaTitle(), + 'description' => $this->getMetaDescription(), + 'image' => $this->getMetaImage(), + 'url' => $this->getMetaUrl(), + ]; + + } + + protected function getMetaTitle(): string + { + return $this->title; + } + + protected function getMetaDescription(): string + { + return strip_tags($this->chapo); + } + + protected function getMetaImage(): string + { + return $this->image('social_preview'); + } + + protected function getMetaUrl(): ?string + { + return request()->url(); + } +} + + + diff --git a/app/Models/LaboArticle.php b/app/Models/LaboArticle.php index 5aaa052..3b1c15c 100644 --- a/app/Models/LaboArticle.php +++ b/app/Models/LaboArticle.php @@ -67,4 +67,6 @@ class LaboArticle extends Model implements Sortable, PillBoxContract { return route('actus-labos.show', ['slug' => $this->slug]); } + + } diff --git a/app/Models/SocialArticle.php b/app/Models/SocialArticle.php index 111d62d..ef02c6b 100644 --- a/app/Models/SocialArticle.php +++ b/app/Models/SocialArticle.php @@ -22,7 +22,7 @@ use A17\Twill\Models\Model; */ class SocialArticle extends Model implements PillBoxContract { - use HasSlug, HasMedias, HasSubscriberOnlyContent; + use HasSlug, HasMedias, HasSubscriberOnlyContent, HasMetaTags; protected $fillable = [ 'published', @@ -44,6 +44,17 @@ class SocialArticle extends Model implements PillBoxContract 'subscriber_only' => 'bool' ]; + public $mediasParams = [ + 'social_preview' => [ + 'default' => [ + [ + 'name' => 'default', + 'ratio' => 1, + ], + ], + ], + ]; + /** * Increments view count diff --git a/resources/views/admin/socialArticles/form.blade.php b/resources/views/admin/socialArticles/form.blade.php index ab847eb..249c16a 100644 --- a/resources/views/admin/socialArticles/form.blade.php +++ b/resources/views/admin/socialArticles/form.blade.php @@ -7,6 +7,12 @@ ] ]) @section('contentFields') + @formField('medias', [ + 'name' => 'social_preview', + 'label' => 'Image de prévisualisation', + 'max' => 1, + ]) + @formField('wysiwyg', [ 'name' => 'chapo', 'label' => 'Chapô', diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 58de6c6..6d22580 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -24,6 +24,21 @@ + + + + @if(isset($meta)) + + + + + + + + + @endif + +
-- 2.39.5