]> _ Git - psq.git/commitdiff
add meta social articel
authorLouis Jeckel <louis.jeckel@outlook.cm>
Mon, 14 Sep 2020 08:50:27 +0000 (10:50 +0200)
committerLouis Jeckel <louis.jeckel@outlook.cm>
Mon, 14 Sep 2020 08:50:27 +0000 (10:50 +0200)
app/Http/Controllers/SocialArticleController.php
app/Models/HasMetaTags.php [new file with mode: 0644]
app/Models/LaboArticle.php
app/Models/SocialArticle.php
resources/views/admin/socialArticles/form.blade.php
resources/views/layouts/app.blade.php

index 75bfdd3b29392ba66de353684b7e0e1a867611cc..7b72546919903f601cc4444c31e1979c8eb18905 100644 (file)
@@ -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 (file)
index 0000000..c8912ad
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+
+namespace App\Models;
+
+
+trait HasMetaTags
+{
+    public function getMetaData(): array
+    {
+        return [
+            'title' => $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();
+    }
+}
+
+
+
index 5aaa052359fbbeaea3ec3efb814d3390136bfba4..3b1c15c8311aabc8751134a4a334508d6abd7ab4 100644 (file)
@@ -67,4 +67,6 @@ class LaboArticle extends Model implements Sortable, PillBoxContract
     {
         return route('actus-labos.show', ['slug' => $this->slug]);
     }
+
+
 }
index 111d62da4b3926de0d255162c4045b58cba31630..ef02c6b2027986742e74ed5761ab1cce00da28e6 100644 (file)
@@ -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
index ab847eba1777fd43338bde23f09e2ff78b374a7d..249c16a6f23c12d03cd44902ce83aec5ad7766b6 100644 (file)
@@ -7,6 +7,12 @@
     ]
 ])
 @section('contentFields')
+    @formField('medias', [
+        'name' => 'social_preview',
+        'label' => 'Image de prévisualisation',
+        'max' => 1,
+    ])
+
     @formField('wysiwyg', [
         'name' => 'chapo',
         'label' => 'Chapô',
index 58de6c605cb88204ae65d1829892a001adff0d68..6d225804f9440cc8d7ecfb739f44b67fabe52de7 100644 (file)
 
     <!-- Styles -->
     <link href="{{ asset('css/app.css') }}" rel="stylesheet">
+
+
+
+    @if(isset($meta))
+        <meta property="og:title" content="{{Arr::get($meta, 'title', 'Prescription Santé - Le Quotidien')}}">
+        <meta property="og:description" content="{{Arr::get($meta, 'description', "L'ACTUALITÉ À LA UNE DE NOTRE QUOTIDIEN")}}">
+        <meta property="og:image" content="{{Arr::get($meta, 'image')}}">
+        <meta property="og:url" content="{{Arr::get($meta, 'url')}}">
+        <meta name="twitter:card" content="summary">
+        <meta property="og:type" content="article" />
+        <meta property="og:locale" content="fr_FR" />
+
+    @endif
+
+
 </head>
 <body>
     <div id="app">