From 491f7d1d20159327b25bde2ae278c2845628389e Mon Sep 17 00:00:00 2001 From: Louis Jeckel Date: Mon, 14 Sep 2020 16:12:16 +0200 Subject: [PATCH] meta on social article and adcampaign --- app/Http/Controllers/ActuLabosController.php | 2 ++ app/Http/Controllers/AdCampaignController.php | 2 ++ app/Models/AdCampaign.php | 26 ++++++++++++++++++- app/Models/HasMetaTags.php | 4 +-- app/Models/LaboArticle.php | 26 ++++++++++++++++++- 5 files changed, 56 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ActuLabosController.php b/app/Http/Controllers/ActuLabosController.php index c5160e6..3dc38b7 100644 --- a/app/Http/Controllers/ActuLabosController.php +++ b/app/Http/Controllers/ActuLabosController.php @@ -19,10 +19,12 @@ class ActuLabosController extends Controller public function show($slug, LaboArticleRepository $repository) { + /** @var LaboArticle $actu */ $actu = $repository->forSlug($slug); \View::share('title', $actu->title); \View::share('actu', $actu); + \View::share('meta', $actu->getMetaData()); return view('actu-labos.show'); } diff --git a/app/Http/Controllers/AdCampaignController.php b/app/Http/Controllers/AdCampaignController.php index bf9ef83..854c0a1 100644 --- a/app/Http/Controllers/AdCampaignController.php +++ b/app/Http/Controllers/AdCampaignController.php @@ -35,9 +35,11 @@ class AdCampaignController extends Controller public function show($slug, AdCampaignRepository $repository) { + /** @var AdCampaign $campaign */ $campaign = $repository->forSlug($slug); \View::share('campaign', $campaign); \View::share('title', $campaign->title); + \View::share('meta', $campaign->getMetaData()); return view('com-campaigns.show'); diff --git a/app/Models/AdCampaign.php b/app/Models/AdCampaign.php index 49054d1..34e8e3e 100644 --- a/app/Models/AdCampaign.php +++ b/app/Models/AdCampaign.php @@ -14,11 +14,15 @@ use Laravel\Scout\Searchable; * Class AdCampaign * @package App\Models * @property string $url + * @property string $title + * @property string $description + * @property string $content + * */ class AdCampaign extends Model implements Sortable, PillBoxContract { use HasSlug, HasMedias, HasPosition, HasSubscriberOnlyContent; - use Searchable; + use Searchable, HasMetaTags; protected $fillable = [ 'published', @@ -52,6 +56,12 @@ class AdCampaign extends Model implements Sortable, PillBoxContract 'ratio' => 0, ], ], + 'social' => [ + [ + 'name' => 'Social', + 'ratio' => 1, + ], + ], ], ]; @@ -88,4 +98,18 @@ class AdCampaign extends Model implements Sortable, PillBoxContract { return route('com-campaign.show', ['slug' => $this->slug]) ?? '#'; } + + /** + * @return string + */ + protected function getMetaDescription(): string + { + return $this->description; + } + + protected function getMetaImage(): string + { + return $this->image('image', 'social', [], true) ?? + $this->image('image', 'preview'); + } } diff --git a/app/Models/HasMetaTags.php b/app/Models/HasMetaTags.php index c8912ad..0572f59 100644 --- a/app/Models/HasMetaTags.php +++ b/app/Models/HasMetaTags.php @@ -10,7 +10,7 @@ trait HasMetaTags { return [ 'title' => $this->getMetaTitle(), - 'description' => $this->getMetaDescription(), + 'description' => strip_tags($this->getMetaDescription()), 'image' => $this->getMetaImage(), 'url' => $this->getMetaUrl(), ]; @@ -24,7 +24,7 @@ trait HasMetaTags protected function getMetaDescription(): string { - return strip_tags($this->chapo); + return $this->chapo; } protected function getMetaImage(): string diff --git a/app/Models/LaboArticle.php b/app/Models/LaboArticle.php index fcb674a..10d0176 100644 --- a/app/Models/LaboArticle.php +++ b/app/Models/LaboArticle.php @@ -18,7 +18,7 @@ use Laravel\Scout\Searchable; */ class LaboArticle extends Model implements Sortable, PillBoxContract { - use HasSlug, HasMedias, HasPosition, HasSubscriberOnlyContent; + use HasSlug, HasMedias, HasPosition, HasSubscriberOnlyContent, HasMetaTags; protected $fillable = [ 'publish_start_date', @@ -46,6 +46,12 @@ class LaboArticle extends Model implements Sortable, PillBoxContract 'ratio' => 0, ], ], + 'social' => [ + [ + 'name' => 'social', + 'ratio' => 1, + ] + ] ], ]; @@ -69,5 +75,23 @@ class LaboArticle extends Model implements Sortable, PillBoxContract return route('actus-labos.show', ['slug' => $this->slug]); } + /** + * @return string + */ + protected function getMetaDescription(): string + { + return $this->preview; + } + + + /** + * @return string + */ + protected function getMetaImage(): string + { + return $this->image('image', 'social', [], true) ?? + $this->image('image'); + } + } -- 2.39.5