Skip to content

Commit

Permalink
Merge pull request #6 from cwsdigital/fix/issue-#2
Browse files Browse the repository at this point in the history
default to no description fallback
  • Loading branch information
chrispymm authored Sep 20, 2021
2 parents 55a343d + 69c4147 commit b059f81
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
tags
.php_cs.cache
.idea

13 changes: 8 additions & 5 deletions src/Models/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,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() {
Expand Down
9 changes: 7 additions & 2 deletions src/Traits/SetsMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
4 changes: 2 additions & 2 deletions src/config/metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

'fallbacks' => [
'title' => 'title',
'description' => '',
'description' => false,
'og_title' => 'title',
'og_description' => '',
'og_description' => false,
'og_type' => 'metadataDefaultOgType',
'card_type' => 'metadataDefaultCardType',
],
Expand Down

0 comments on commit b059f81

Please sign in to comment.