From a9df6bad864394a24858977544c194cdc99b6ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20M=2E?= Date: Thu, 15 Aug 2024 10:56:05 +0200 Subject: [PATCH] Add seoValue --- src/Views/Concerns/WithSeo.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Views/Concerns/WithSeo.php b/src/Views/Concerns/WithSeo.php index b4d11532..b8d47736 100644 --- a/src/Views/Concerns/WithSeo.php +++ b/src/Views/Concerns/WithSeo.php @@ -6,16 +6,23 @@ trait WithSeo { - use SEOTools; - public function bootWithSeo(): void { - if (method_exists(static::class, 'getTitle')) { - $this->seo()->setTitle(static::getTitle()); + SEOMeta::setTitle($this->seoValue('getTitle')); + SEOMeta::setDescription($this->seoValue('getDescription')); + SEOMeta::setRobots($this->seoValue('getRobots')); + } + + protected function seoValue(mixed $value, mixed $default = null): mixed + { + if ($value instanceof Closure) { + return value($value) ?? $default; } - if (method_exists(static::class, 'getDescription')) { - $this->seo()->setDescription(static::getDescription()); + if (method_exists(static::class, $value)) { + return strip_tags($this->$value()); } + + return $default; } }