Skip to content

Commit

Permalink
default to no description fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispymm committed Sep 17, 2021
1 parent ed13fe2 commit 667d64b
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,2 +1,3 @@
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 @@ -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() {
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 667d64b

Please sign in to comment.