Skip to content

Commit dbe299a

Browse files
committed
some sites have meta-keywords separated by spaces
1 parent fda36fb commit dbe299a

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

demo/index.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ function printCode($code, $asHtml = true)
7070
'description' => 'printText',
7171
'url' => 'printUrl',
7272
'type' => 'printText',
73+
'tags' => 'printArray',
7374
'imagesUrls' => 'printArray',
7475
'code' => 'printCode',
7576
'source' => 'printUrl',
@@ -88,6 +89,7 @@ function printCode($code, $asHtml = true)
8889
'description' => 'printText',
8990
'url' => 'printUrl',
9091
'type' => 'printText',
92+
'tags' => 'printArray',
9193
'image' => 'printImage',
9294
'imageWidth' => 'printText',
9395
'imageHeight' => 'printText',

src/Providers/Html.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,21 @@ public function getType()
7070
*/
7171
public function getTags()
7272
{
73-
return $this->bag->has('keywords') ? array_map('trim', explode(',',$this->bag->get('keywords'))) : [];
73+
$keywords = $this->bag->get('keywords');
74+
75+
if (!$keywords) {
76+
return [];
77+
}
78+
79+
//some sites, contains the keywords separated by commas
80+
if (strpos($keywords, ',')) {
81+
$keywords = explode(',', $keywords);
82+
//and others by spaces (ex: youtube)
83+
} else {
84+
$keywords = explode(' ', $keywords);
85+
}
86+
87+
return array_filter(array_map('trim', $keywords));
7488
}
7589

7690

src/Providers/OpenGraph.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public function run()
3333

3434
if ($name === 'image') {
3535
$this->bag->add('images', $value);
36+
} else if (strpos($name, ':tag') !== false) {
37+
$this->bag->add('tags', $value);
3638
} else {
3739
$this->bag->set($name, $value);
3840
}
@@ -126,6 +128,14 @@ public function getUrl()
126128
return $this->bag->get('url');
127129
}
128130

131+
/**
132+
* {@inheritdoc}
133+
*/
134+
public function getTags()
135+
{
136+
return $this->bag->get('tags') ?: [];
137+
}
138+
129139
/**
130140
* {@inheritdoc}
131141
*/

0 commit comments

Comments
 (0)