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

Support extra tags

This commit is contained in:
Samuel Štancl 2021-05-26 13:02:20 +02:00
parent 21452f538b
commit 007a555d57
3 changed files with 41 additions and 0 deletions

View file

@ -5,6 +5,10 @@
@if(seo('description')) <meta property="og:description" content="@seo('description')" /> @endif
@if(seo('image')) <meta property="og:image" content="@seo('image')" /> @endif
@foreach(seo()->tags() as $tag)
{!! $tag !!}
@endforeach
@foreach(seo()->extensions() as $extension)
<x-dynamic-component :component="$extension" />
@endforeach

View file

@ -37,6 +37,9 @@ class SEOManager
/** Metadata for additional features. */
protected array $meta = [];
/** Extra head tags. */
protected array $tags = [];
/** Get all used values. */
public function all(): array
{
@ -169,6 +172,28 @@ class SEOManager
return $this->set('image', "https://s.useflipp.com/{$template}.png?s={$signature}&v={$query}");
}
/** Get all extra head tags. */
public function tags(): array
{
return $this->tags;
}
/** Add a head tag. */
public function rawTag(string $tag): static
{
$this->tags[] = $tag;
return $this;
}
/** Add a meta tag. */
public function tag(string $property, string $content): static
{
$this->rawTag("<meta property\"{$property}\" content=\"{$content}\" />");
return $this;
}
/**
* Get or set metadata.
* @param string|array $key The key or key-value pair being set.

View file

@ -82,3 +82,15 @@ test('thunks can be used as defaults', function () {
test('setting the defaults returns the manager instance', function () {
expect(seo()->title(default: 'foo'))->toBeInstanceOf(SEOManager::class);
});
test('meta tags can be added to the template', function () {
seo()->tag('fb:image', 'foo');
expect(meta())->toContain('<meta property="fb:image" content="foo" />');
});
test('raw tags can be added to the template', function () {
seo()->rawTag('<meta foo bar>');
expect(meta())->toContain('<meta foo bar>');
});