From f6bb4e8f64bbd7ee0dc68b511c04d1da0d2b3989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Wed, 23 Mar 2022 19:19:52 +0100 Subject: [PATCH] Allow setting tag('og:title', ...) --- assets/views/components/meta.blade.php | 9 +++++++-- composer.json | 7 ++++++- src/SEOManager.php | 12 ++++++++++++ tests/Pest/ManagerTest.php | 9 +++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/assets/views/components/meta.blade.php b/assets/views/components/meta.blade.php index 3998ea6..cdb618f 100644 --- a/assets/views/components/meta.blade.php +++ b/assets/views/components/meta.blade.php @@ -1,9 +1,14 @@ @if(seo('title')) @seo('title') - + + @if(seo()->hasTag('og:title')) + + @else + + @endif @endif -@if(seo('description')) +@if(seo('description')) @endif diff --git a/composer.json b/composer.json index df3a55a..02229b5 100644 --- a/composer.json +++ b/composer.json @@ -42,5 +42,10 @@ } }, "minimum-stability": "dev", - "prefer-stable": true + "prefer-stable": true, + "config": { + "allow-plugins": { + "pestphp/pest-plugin": true + } + } } diff --git a/src/SEOManager.php b/src/SEOManager.php index cbd8fd4..9eb98a3 100644 --- a/src/SEOManager.php +++ b/src/SEOManager.php @@ -201,6 +201,18 @@ class SEOManager return $this->tags; } + /** Has a specific tag been set? */ + public function hasRawTag(string $key): bool + { + return array_key_exists($key, $this->tags); + } + + /** Has a specific meta tag been set? */ + public function hasTag(string $property): bool + { + return $this->hasRawTag("meta.{$property}"); + } + /** Add a head tag. */ public function rawTag(string $key, string $tag = null): static { diff --git a/tests/Pest/ManagerTest.php b/tests/Pest/ManagerTest.php index f404c9b..860cad6 100644 --- a/tests/Pest/ManagerTest.php +++ b/tests/Pest/ManagerTest.php @@ -127,3 +127,12 @@ test('canonical url can be changed', function () { ->toContain('') ->toContain(''); }); + +test('og:title can be overridden as a tag', function () { + seo()->title('foo') + ->tag('og:title', 'bar'); + + expect(meta()) + ->toContain('foo') + ->toContain(''); +});