diff --git a/.gitignore b/.gitignore index 5826402..2f6559f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ composer.phar composer.lock .DS_Store +.idea/ diff --git a/src/Torann/LaravelMetaTags/MetaTag.php b/src/Torann/LaravelMetaTags/MetaTag.php index f804242..706aae6 100644 --- a/src/Torann/LaravelMetaTags/MetaTag.php +++ b/src/Torann/LaravelMetaTags/MetaTag.php @@ -232,21 +232,32 @@ public function twitterCard() } /** + * Set the title. The configured site title is appended when appropriate. + * * @param string $value * @return string */ private function setTitle($value) { - $title = $this->title; + // The configured site title is the base title + $title = $this->config['title']; + // Default limit is to pass to cut() + $limit = 'title'; + if (!$title || $title === $value) { + // Don't append anything to the provided value, title is empty + // or the same as the provided value + return $this->metas['title'] = self::cut($value, $limit); + } + + // Concat configured separator and base title + $title = sprintf(' %s %s', $this->config['title_separator'], $title); - if ($title && $this->config['title_limit']) { - $title = ' - '.$title; + if ($this->config['title_limit']) { + // Deduct append value from the title limit $limit = $this->config['title_limit'] - strlen($title); } - else { - $limit = 'title'; - } + // Set and return the concatenated title value return $this->metas['title'] = self::cut($value, $limit).$title; } diff --git a/src/Torann/LaravelMetaTags/MetaTagsServiceProvider.php b/src/Torann/LaravelMetaTags/MetaTagsServiceProvider.php index 10e2028..9ea70ca 100644 --- a/src/Torann/LaravelMetaTags/MetaTagsServiceProvider.php +++ b/src/Torann/LaravelMetaTags/MetaTagsServiceProvider.php @@ -32,6 +32,9 @@ public function boot() */ public function register() { + $configPath = __DIR__ . '/../../config/config.php'; + $this->mergeConfigFrom($configPath, 'meta-tags'); + $this->app['metatag'] = $this->app->share(function ($app) { return new MetaTag( $app['request'], diff --git a/src/config/config.php b/src/config/config.php index 61e1675..664527b 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -22,6 +22,17 @@ 'title_limit' => 70, + /* + |-------------------------------------------------------------------------- + | Title separator + |-------------------------------------------------------------------------- + | + | The separator between the page title and the site default title. + | + */ + + 'title_separator' => '|', + /* |-------------------------------------------------------------------------- | Limit description meta tag length