Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore functionality where set site title is appended to title value #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
composer.phar
composer.lock
.DS_Store
.idea/
23 changes: 17 additions & 6 deletions src/Torann/LaravelMetaTags/MetaTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Torann/LaravelMetaTags/MetaTagsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
11 changes: 11 additions & 0 deletions src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down