Skip to content

Commit

Permalink
Merged develop with separator
Browse files Browse the repository at this point in the history
  • Loading branch information
eusonlito committed May 10, 2022
2 parents 2d2dee4 + 6ed57c6 commit 73edf12
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Eusonlito/LaravelMeta/Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class Meta
'title_limit' => 70,
'description_limit' => 200,
'image_limit' => 5,
'tags' => ['Tag', 'MetaName', 'MetaProperty', 'MetaProduct', 'TwitterCard']
'tags' => ['Tag', 'MetaName', 'MetaProperty', 'MetaProduct', 'TwitterCard'],
'separator' => ' - '
];

/**
Expand All @@ -39,6 +40,7 @@ class Meta

/**
* @param array $config = []
*
* @return object
*/
public static function getInstance(array $config = [])
Expand Down Expand Up @@ -109,14 +111,15 @@ public function title($title = null)
public function set($key, $value)
{
if (!is_array($value)) {
$value = $this->plain($value);
$value = $this->plain($value);
}

$method = 'set'.$key;

if (method_exists($this, $method)) {
return $this->$method($value);
}

return $this->metas[$key] = self::cut($value, $key);
}

Expand Down Expand Up @@ -146,7 +149,7 @@ protected function setTitle($value)
$title = $this->title;

if ($title && $this->config['title_limit']) {
$title = ' - '.$title;
$title = $this->config['separator'].$title;
$limit = $this->config['title_limit'] - mb_strlen($title);
} else {
$limit = 'title';
Expand Down Expand Up @@ -229,9 +232,8 @@ public function getImage($default)

return array_slice(array_merge($this->metas['image'], $default), 0, $this->config['image_limit']);
}

/**
* @param string|array $default
*
* @return array
*/
public function getProduct()
Expand Down
11 changes: 11 additions & 0 deletions src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,15 @@
*/

'tags' => ['Tag', 'MetaName', 'MetaProperty', 'MetaProduct', 'TwitterCard'],

/*
|--------------------------------------------------------------------------
| Strings Separator
|--------------------------------------------------------------------------
|
| Use this string to separate default and custom title.
|
*/

'separator' => ' - ',
];

0 comments on commit 73edf12

Please sign in to comment.