From 94be0f7e06a5f88b8057e5a5f8d09f7117982b4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Wed, 30 Mar 2022 00:50:40 +0200 Subject: [PATCH] Add type() --- assets/views/components/meta.blade.php | 7 ++++--- src/SEOManager.php | 3 ++- tests/Pest/ManagerTest.php | 8 +++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/assets/views/components/meta.blade.php b/assets/views/components/meta.blade.php index e15a13b..a09a228 100644 --- a/assets/views/components/meta.blade.php +++ b/assets/views/components/meta.blade.php @@ -12,10 +12,11 @@ @endif -@unless(seo()->hasTag('og:type')) - {{-- If an og:type tag is provided directly, it's included in the @foreach below --}} +@if(seo('type')) + +@else -@endunless +@endif @if(seo('site')) @endif diff --git a/src/SEOManager.php b/src/SEOManager.php index 01294aa..68d6d68 100644 --- a/src/SEOManager.php +++ b/src/SEOManager.php @@ -13,6 +13,7 @@ use Illuminate\Support\Str; * @method $this url(string $url = null, ...$args) Set the canonical URL. * @method $this site(string $site = null, ...$args) Set the site name. * @method $this image(string $url = null, ...$args) Set the cover image. + * @method $this type(string $type = null, ...$args) Set the page type. * @method $this twitter(enabled $bool = true, ...$args) Enable the Twitter extension. * @method $this twitterSite(string $username = null, ...$args) Set the Twitter author. * @method $this twitterTitle(string $title = null, ...$args) Set the Twitter title. @@ -53,7 +54,7 @@ class SEOManager protected function getKeys(): array { return collect([ - 'site', 'title', 'image', 'description', 'url', + 'site', 'title', 'image', 'description', 'url', 'type', 'twitter.site', 'twitter.title', 'twitter.image', 'twitter.description', ]) ->merge(array_keys($this->defaults)) diff --git a/tests/Pest/ManagerTest.php b/tests/Pest/ManagerTest.php index 31332b6..f99bf91 100644 --- a/tests/Pest/ManagerTest.php +++ b/tests/Pest/ManagerTest.php @@ -137,10 +137,12 @@ test('og:title can be overridden using a tag', function () { ->toContain(''); }); -test('og:type can be overridden using a tag', function () { +test('type can be overridden using the type method', function () { expect(meta())->toContain(''); // default - seo()->tag('og:type', 'foo'); + seo()->type('foo'); - expect(meta())->toContain(''); // overridden + expect(meta()) + ->toContain('') // overridden + ->not()->toContain('website'); });