From 5729da6e6d34a7da1969181e3f40d31e3c237d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Wed, 26 May 2021 21:17:58 +0200 Subject: [PATCH] Support keys for rawTag() --- README.md | 1 + src/SEOManager.php | 8 +++++--- tests/Pest/ManagerTest.php | 9 ++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e1ff3f9..b9a8c59 100644 --- a/README.md +++ b/README.md @@ -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(''); +seo()->rawTag('fb_url', ''); // Keyed, allows overrides later on ``` ### Canonical URL diff --git a/src/SEOManager.php b/src/SEOManager.php index 53ee799..82f42b9 100644 --- a/src/SEOManager.php +++ b/src/SEOManager.php @@ -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(""); + $this->rawTag("meta.{$property}", ""); return $this; } diff --git a/tests/Pest/ManagerTest.php b/tests/Pest/ManagerTest.php index c12a040..50840b2 100644 --- a/tests/Pest/ManagerTest.php +++ b/tests/Pest/ManagerTest.php @@ -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(''); + seo()->rawTag('foo', ''); expect(meta())->toContain(''); }); +test('raw tags can be overridden', function () { + seo()->rawTag('foo', ''); + seo()->rawTag('foo', ''); + + expect(meta())->toContain(''); +}); + test('canonical url is not included by default', function () { expect(meta()) ->not()->toContain('og:url')