From 667d64b7745b484a048ae7ec2eaa4428a73e64cc Mon Sep 17 00:00:00 2001 From: Chris Pymm Date: Fri, 17 Sep 2021 22:08:09 +0100 Subject: [PATCH] default to no description fallback --- .gitignore | 1 + src/Models/Metadata.php | 13 ++++++++----- src/Traits/SetsMetadata.php | 9 +++++++-- src/config/metadata.php | 4 ++-- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index a2d70b7..386cceb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ tags .php_cs.cache +.idea \ No newline at end of file diff --git a/src/Models/Metadata.php b/src/Models/Metadata.php index 0e16b87..a7bbe27 100644 --- a/src/Models/Metadata.php +++ b/src/Models/Metadata.php @@ -70,18 +70,21 @@ public function field($column) } } - protected function getFallbackValue($column) { - if( !array_key_exists($column, $this->fallbacks()) ) { - return; + protected function getFallbackValue($column) + { + if (!array_key_exists($column, $this->fallbacks())) { + return false; } $fallback = $this->fallbacks()[$column]; - if($column == 'title' || $column == 'og_title') { + + if ($column == 'title' || $column == 'og_title') { $site_title = app(SettingRepository::class)->byKey('site_title', 'seo'); - return strip_tags($this->meta_describable->$fallback) . ($site_title ? ' - '. $site_title : ''); + return strip_tags($this->meta_describable->$fallback).($site_title ? ' - '.$site_title : ''); } else { return strip_tags($this->meta_describable->$fallback); } + } protected function fallbacks() { diff --git a/src/Traits/SetsMetadata.php b/src/Traits/SetsMetadata.php index 730b871..1071e4c 100644 --- a/src/Traits/SetsMetadata.php +++ b/src/Traits/SetsMetadata.php @@ -11,10 +11,15 @@ public function setMetadata(Model $describable, array $metadata=[]) { $request = request(); SEOTools::setTitle($metadata->field('title')); - SEOTools::setDescription($metadata->field('description')); + if( $metadata->field('description') ) { + SEOTools::setDescription($metadata->field('description')); + } SEOTools::opengraph()->setTitle($metadata->field('og_title')); - SEOTools::opengraph()->setDescription($metadata->field('og_description')); + + if($metadata->field('og_description')) { + SEOTools::opengraph()->setDescription($metadata->field('og_description')); + } SEOTools::opengraph()->addProperty('type', $metadata->field('og_type')); diff --git a/src/config/metadata.php b/src/config/metadata.php index 50b2aeb..d60d164 100644 --- a/src/config/metadata.php +++ b/src/config/metadata.php @@ -4,9 +4,9 @@ 'fallbacks' => [ 'title' => 'title', - 'description' => '', + 'description' => false, 'og_title' => 'title', - 'og_description' => '', + 'og_description' => false, 'og_type' => 'metadataDefaultOgType', 'card_type' => 'metadataDefaultCardType', ],