Skip to content

Commit 4b60e52

Browse files
committed
Merge pull request #15 from sdeering/master
fixes issue #14 - added title_seperator get/set
2 parents 14f130d + 60ffab0 commit 4b60e52

File tree

3 files changed

+64
-13
lines changed

3 files changed

+64
-13
lines changed

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
SEOTools is a package for **Laravel 5** that provides helpers for some common SEO techniques.
44

5-
> Current Build Status
5+
> Current Build Status
66
77
[![Build Status](https://travis-ci.org/artesaos/seotools.svg)](https://travis-ci.org/artesaos/seotools)
88
[![Code Climate](https://codeclimate.com/github/artesaos/seotools/badges/gpa.svg)](https://codeclimate.com/github/artesaos/seotools)
@@ -53,10 +53,10 @@ In order to use the `SEOMeta` facade, you need to register it on the `config/app
5353
```
5454
## 4 - Usage
5555
### Meta tags Generator
56-
With **SEOMeta** you can create meta tags to the `head`
56+
With **SEOMeta** you can create meta tags to the `head`
5757

5858
### Opengraph tags Generator
59-
With **OpenGraph** you can create opengraph tags to the `head`
59+
With **OpenGraph** you can create opengraph tags to the `head`
6060

6161
#### In your controller
6262
```php
@@ -72,7 +72,7 @@ class CommomController extends Controller
7272
{
7373
SEOMeta::setTitle('Home');
7474
SEOMeta::setDescription('This is my page description');
75-
75+
7676
OpenGraph::setDescription('This is my page description');
7777
OpenGraph::setTitle('Home');
7878
OpenGraph::setUrl('http://current.url.com');
@@ -95,14 +95,14 @@ class CommomController extends Controller
9595
SEOMeta::addMeta('article:published_time', $post->published_date->toW3CString(), 'property');
9696
SEOMeta::addMeta('article:section', $post->category, 'property');
9797
SEOMeta::addKeyword(['key1', 'key2', 'key3']);
98-
98+
9999
OpenGraph::setDescription($post->title);
100100
OpenGraph::setTitle($post->resume);
101101
OpenGraph::setUrl('http://current.url.com');
102102
OpenGraph::addProperty('type', 'article');
103103
OpenGraph::addProperty('locale', 'pt-br');
104104
OpenGraph::addProperty('locale:alternate', ['pt-pt', 'en-us']);
105-
105+
106106
OpenGraph::addImage($post->cover->url);
107107
OpenGraph::addImage($post->images->list('url'));
108108
OpenGraph::addImage(['url' => 'http://image.url.com/cover.jpg', 'size' => 300]);
@@ -134,7 +134,7 @@ class CommomController extends Controller
134134
<meta name='keywords' content='key1, key2, key3' />
135135
<meta property='article:published_time' content='2015-01-31T20:30:11-02:00' />
136136
<meta property='article:section' content='news' />
137-
137+
138138
<meta property="og:description"content="description..." />
139139
<meta property="og:title"content="Title" />
140140
<meta property="og:url"content="http://current.url.com" />
@@ -156,7 +156,7 @@ class CommomController extends Controller
156156
</html>
157157
```
158158

159-
#### Configuration
159+
#### Configuration
160160
In `seotools.php` configuration file you can determine the properties of the default values and some behaviors.
161161
- meta
162162
- **defaults** - What values are displayed if not specified any value for the page display. If the value is `false`, nothing is displayed.
@@ -166,6 +166,7 @@ In `seotools.php` configuration file you can determine the properties of the def
166166

167167
#### API (SEOMeta)
168168
```php
169+
SEOMeta::setTitleSeperator($seperator);
169170
SEOMeta::setTitle($title);
170171
SEOMeta::setDescription($description);
171172
SEOMeta::setKeywords($keywords);
@@ -182,6 +183,7 @@ SEOMeta::setTitle($title)
182183
// Retrieving data
183184
SEOMeta::getTitle();
184185
SEOMeta::getTitleSession();
186+
SEOMeta::getTitleSeperator();
185187
SEOMeta::getKeywords();
186188
SEOMeta::getDescription();
187189
SEOMeta::reset();
@@ -196,7 +198,7 @@ OpenGraph::addImage($url); // add image url
196198
OpenGraph::addImages($url); // add an array of url images
197199
OpenGraph::setTitle($title); // define title
198200
OpenGraph::setDescription($description); // define description
199-
OpenGraph::setUrl($url); // define url
201+
OpenGraph::setUrl($url); // define url
200202
OpenGraph::setSiteName($name); //define site_name
201203

202204
// You can concatenate methods

src/SEOTools/Contracts/MetaTags.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ public function generate();
2626
*/
2727
public function setTitle($title);
2828

29+
/**
30+
* Set the title seperator.
31+
*
32+
* @param string $seperator
33+
*
34+
* @return MetaTagsContracts
35+
*/
36+
public function setTitleSeperator($seperator);
37+
2938
/**
3039
* Set the description.
3140
*
@@ -79,6 +88,13 @@ public function getTitle();
7988
*/
8089
public function getTitleSession();
8190

91+
/**
92+
* Get the title seperator that was set.
93+
*
94+
* @return string
95+
*/
96+
public function getTitleSeperator();
97+
8298
/**
8399
* Get the Meta keywords.
84100
*

src/SEOTools/SEOMeta.php

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ class SEOMeta implements MetaTagsContract
1919
*/
2020
protected $title_session;
2121

22+
/**
23+
* The title tag seperator.
24+
*
25+
* @var array
26+
*/
27+
protected $title_seperator;
28+
2229
/**
2330
* The meta description.
2431
*
@@ -81,11 +88,11 @@ public function generate()
8188
$metatags = $this->metatags;
8289

8390
$html = [];
84-
91+
8592
if($title):
8693
$html[] = "<title>$title</title>";
8794
endif;
88-
95+
8996
if($title):
9097
$html[] = "<meta name=\"description\" itemprop=\"description\" content=\"{$description}\" />";
9198
endif;
@@ -125,6 +132,21 @@ public function setTitle($title)
125132
return $this;
126133
}
127134

135+
/**
136+
* Sets the seperator for the title tag.
137+
*
138+
* @param string $seperator
139+
*
140+
* @return MetaTagsContract
141+
*/
142+
public function setTitleSeperator($seperator)
143+
{
144+
// sets the title seperator ie - title <seperator> <site>
145+
$this->title_seperator = $seperator;
146+
147+
return $this;
148+
}
149+
128150
/**
129151
* @param string $description
130152
*
@@ -220,6 +242,16 @@ public function getTitleSession()
220242
return $this->title_session ?: $this->getTitle();
221243
}
222244

245+
/**
246+
* takes the title that was set
247+
*
248+
* @return string
249+
*/
250+
public function getTitleSeperator()
251+
{
252+
return $this->title_seperator ?: $this->config->get('defaults.separator', ' - ');
253+
}
254+
223255
/**
224256
* Get the Meta keywords.
225257
*
@@ -262,7 +294,7 @@ public function reset()
262294
*/
263295
protected function parseTitle($title)
264296
{
265-
return $title . $this->config->get('defaults.separator', ' | ') . $this->config->get('defaults.title', null);
297+
return $title . $this->getTitleSeperator() . $this->config->get('defaults.title', null);
266298
}
267299

268300
protected function loadWebMasterTags()
@@ -274,4 +306,5 @@ protected function loadWebMasterTags()
274306
endif;
275307
endforeach;
276308
}
277-
}
309+
310+
}

0 commit comments

Comments
 (0)