1
0
Fork 0
mirror of https://github.com/archtechx/laravel-seo.git synced 2025-12-12 01:44:03 +00:00

Support keys for rawTag()

This commit is contained in:
Samuel Štancl 2021-05-26 21:17:58 +02:00
parent 0ebc50cad9
commit 5729da6e6d
3 changed files with 14 additions and 4 deletions

View file

@ -116,6 +116,7 @@ To add more tags to the head, you can use the `tag()` and `rawTag()` methods:
```php
seo()->tag('fb:image', asset('foo'));
seo()->rawTag('<meta property="fb:url" content="bar" />');
seo()->rawTag('fb_url', '<meta property="fb:url" content="bar" />'); // Keyed, allows overrides later on
```
### Canonical URL

View file

@ -191,9 +191,11 @@ class SEOManager
}
/** Add a head tag. */
public function rawTag(string $tag): static
public function rawTag(string $key, string $tag = null): static
{
$this->tags[] = $tag;
$tag ??= $key;
$this->tags[$tag] = $tag;
return $this;
}
@ -201,7 +203,7 @@ class SEOManager
/** Add a meta tag. */
public function tag(string $property, string $content): static
{
$this->rawTag("<meta property=\"{$property}\" content=\"{$content}\" />");
$this->rawTag("meta.{$property}", "<meta property=\"{$property}\" content=\"{$content}\" />");
return $this;
}

View file

@ -90,11 +90,18 @@ test('meta tags can be added to the template', function () {
});
test('raw tags can be added to the template', function () {
seo()->rawTag('<meta foo bar>');
seo()->rawTag('foo', '<meta foo bar>');
expect(meta())->toContain('<meta foo bar>');
});
test('raw tags can be overridden', function () {
seo()->rawTag('foo', '<meta abc>');
seo()->rawTag('foo', '<meta def>');
expect(meta())->toContain('<meta abc>');
});
test('canonical url is not included by default', function () {
expect(meta())
->not()->toContain('og:url')