From f4ec8c0fab6407bcd1d9d92b9e4b6c9d3852e225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1csek=20Tam=C3=A1s?= Date: Sat, 23 Nov 2024 00:38:17 +0100 Subject: [PATCH 1/3] Update meta tags to be HTML5 compliant by removing self-closing slashes (#39) * Update meta tags to be HTML5 compliant by removing self-closing slashes * fix: Undo autoformatting --------- Co-authored-by: machot --- resources/views/components/meta.blade.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/resources/views/components/meta.blade.php b/resources/views/components/meta.blade.php index ed5d44f..0be1bdb 100644 --- a/resources/views/components/meta.blade.php +++ b/resources/views/components/meta.blade.php @@ -3,34 +3,34 @@ @unless(seo()->hasTag('og:title')) {{-- If an og:title tag is provided directly, it's included in the @foreach below --}} - + @endunless @endif @if(seo('description')) - - + + @endif @if(seo('keywords')) - + @endif @if(seo('type')) - + @else - + @endif -@if(seo('site')) @endif +@if(seo('site')) @endif -@if(seo('locale')) @endif +@if(seo('locale')) @endif -@if(seo('image')) @endif +@if(seo('image')) @endif @if(seo('url')) - - + + @endif @foreach(seo()->tags() as $tag) From c768bb7d6026b6fe816b9dc16e1a4b464796d423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Sat, 23 Nov 2024 00:45:49 +0100 Subject: [PATCH 2/3] fix tests broken by #39 --- README.md | 4 ++-- .../components/extensions/twitter.blade.php | 10 +++++----- src/SEOManager.php | 2 +- tests/Pest/ExtensionTest.php | 4 ++-- tests/Pest/ManagerTest.php | 18 +++++++++--------- tests/Pest/SanitizationTest.php | 12 ++++++------ tests/views/components/facebook.blade.php | 2 +- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 71a7b1a..de652c4 100644 --- a/README.md +++ b/README.md @@ -140,8 +140,8 @@ To add more tags to the document head, you can use the `tag()` and `rawTag()` me ```php seo()->tag('fb:image', asset('foo')); -seo()->rawTag(''); -seo()->rawTag('fb_url', ''); // Keyed, allows overrides later on +seo()->rawTag(''); +seo()->rawTag('fb_url', ''); // Keyed, allows overrides later on ``` ### Canonical URL diff --git a/resources/views/components/extensions/twitter.blade.php b/resources/views/components/extensions/twitter.blade.php index 661ddb4..2adcf5a 100644 --- a/resources/views/components/extensions/twitter.blade.php +++ b/resources/views/components/extensions/twitter.blade.php @@ -1,6 +1,6 @@ -@if(seo('twitter.creator')) @endif -@if(seo('twitter.site')) @endif -@if(seo('twitter.title')) @endif -@if(seo('twitter.description')) @endif -@if(seo('twitter.image')) @endif +@if(seo('twitter.creator')) @endif +@if(seo('twitter.site')) @endif +@if(seo('twitter.title')) @endif +@if(seo('twitter.description')) @endif +@if(seo('twitter.image')) @endif diff --git a/src/SEOManager.php b/src/SEOManager.php index 2cfd4c4..ce2df3a 100644 --- a/src/SEOManager.php +++ b/src/SEOManager.php @@ -264,7 +264,7 @@ class SEOManager { $content = e($content); - $this->rawTag("meta.{$property}", ""); + $this->rawTag("meta.{$property}", ""); return $this; } diff --git a/tests/Pest/ExtensionTest.php b/tests/Pest/ExtensionTest.php index caefdba..22be51a 100644 --- a/tests/Pest/ExtensionTest.php +++ b/tests/Pest/ExtensionTest.php @@ -40,7 +40,7 @@ test('extensions can use custom blade paths', function () { seo()->facebookTitle('abc'); - expect(meta())->toContain(''); + expect(meta())->toContain(''); }); test('twitter falls back to the default values', function () { @@ -56,7 +56,7 @@ test('twitter falls back to the default values', function () { expect(seo('twitter.description'))->toBe('bar'); expect(seo('description'))->toBe('baz'); - expect(meta())->toContain(''); + expect(meta())->toContain(''); }); test('extensions are automatically enabled when values for them are set', function () { diff --git a/tests/Pest/ManagerTest.php b/tests/Pest/ManagerTest.php index aa9f25b..a78b165 100644 --- a/tests/Pest/ManagerTest.php +++ b/tests/Pest/ManagerTest.php @@ -86,7 +86,7 @@ test('setting the defaults returns the manager instance', function () { test('meta tags can be added to the template', function () { seo()->tag('fb:image', 'foo'); - expect(meta())->toContain(''); + expect(meta())->toContain(''); }); test('raw tags can be added to the template', function () { @@ -114,8 +114,8 @@ test('canonical url can be read from request', function () { seo()->withUrl(); expect(meta()) - ->toContain('') - ->toContain(''); + ->toContain('') + ->toContain(''); }); test('canonical url can be changed', function () { @@ -124,8 +124,8 @@ test('canonical url can be changed', function () { seo()->url('http://foo.com/bar'); expect(meta()) - ->toContain('') - ->toContain(''); + ->toContain('') + ->toContain(''); }); test('og:title can be overridden using a tag', function () { @@ -134,16 +134,16 @@ test('og:title can be overridden using a tag', function () { expect(meta()) ->toContain('foo') - ->toContain(''); + ->toContain(''); }); test('type can be overridden using the type method', function () { - expect(meta())->toContain(''); // default + expect(meta())->toContain(''); // default seo()->type('foo'); expect(meta()) - ->toContain('') // overridden + ->toContain('') // overridden ->not()->toContain('website'); }); @@ -155,5 +155,5 @@ test('og:locale is not included by default', function () { test('og:locale can be added to the template', function () { seo()->locale('de_DE'); - expect(meta())->toContain(''); + expect(meta())->toContain(''); }); diff --git a/tests/Pest/SanitizationTest.php b/tests/Pest/SanitizationTest.php index b1daa82..b2b420f 100644 --- a/tests/Pest/SanitizationTest.php +++ b/tests/Pest/SanitizationTest.php @@ -13,8 +13,8 @@ test('opengraph methods properly sanitize input', function (string $method, stri expect($meta)->not()->toContain('content="Testing string " with several \' XSS characters " . \' ."'); expect($meta)->not()->toContain("content=\"{$unsanitizedContent}\""); - expect($meta)->toContain(""); - expect($meta)->toContain(""); + expect($meta)->toContain(""); + expect($meta)->toContain(""); })->with([ ['site', 'og:site_name'], ['url', 'og:url'], @@ -37,8 +37,8 @@ test('the twitter extension properly sanitizes input', function (string $method, expect($meta)->not()->toContain('content="Testing string " with several \' XSS characters " . \' ."'); expect($meta)->not()->toContain("content=\"{$unsanitizedContent}\""); - expect($meta)->toContain(""); - expect($meta)->toContain(""); + expect($meta)->toContain(""); + expect($meta)->toContain(""); })->with([ ['twitterCreator', 'twitter:creator'], ['twitterSite', 'twitter:site'], @@ -65,8 +65,8 @@ test('the title method properly sanitizes both tags', function () { expect($meta)->toContain("{$sanitizedContent}"); expect($meta)->toContain("Testing string " with several ' XSS characters </title> " . ' ."); - expect($meta)->toContain(""); - expect($meta)->toContain(""); + expect($meta)->toContain(""); + expect($meta)->toContain(""); }); test('seo blade directive calls are sanitized', function () { diff --git a/tests/views/components/facebook.blade.php b/tests/views/components/facebook.blade.php index 170548c..0333ed2 100644 --- a/tests/views/components/facebook.blade.php +++ b/tests/views/components/facebook.blade.php @@ -1 +1 @@ - + From f6fd5f4a551313926acf991f0f225ae6c3199cd1 Mon Sep 17 00:00:00 2001 From: l3aro Date: Sat, 23 Nov 2024 06:46:28 +0700 Subject: [PATCH 3/3] Correct nullable type (#40) --- src/SEOManager.php | 36 ++++++++++++++++++------------------ src/helpers.php | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/SEOManager.php b/src/SEOManager.php index ce2df3a..a24d0c2 100644 --- a/src/SEOManager.php +++ b/src/SEOManager.php @@ -9,20 +9,20 @@ use Illuminate\Support\Arr; use Illuminate\Support\Str; /** - * @method $this title(string $title = null, ...$args) Set the title. - * @method $this description(string $description = null, ...$args) Set the description. - * @method $this keywords(string $keywords = null, ...$args) Set the keywords. - * @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 locale(string $locale = null, ...$args) Set the page locale. + * @method $this title(?string $title = null, ...$args) Set the title. + * @method $this description(?string $description = null, ...$args) Set the description. + * @method $this keywords(?string $keywords = null, ...$args) Set the keywords. + * @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 locale(?string $locale = null, ...$args) Set the page locale. * @method $this twitter(bool $enabled = true, ...$args) Enable the Twitter extension. - * @method $this twitterCreator(string $username = null, ...$args) Set the Twitter author. - * @method $this twitterSite(string $username = null, ...$args) Set the Twitter author. - * @method $this twitterTitle(string $title = null, ...$args) Set the Twitter title. - * @method $this twitterDescription(string $description = null, ...$args) Set the Twitter description. - * @method $this twitterImage(string $url = null, ...$args) Set the Twitter cover image. + * @method $this twitterCreator(?string $username = null, ...$args) Set the Twitter author. + * @method $this twitterSite(?string $username = null, ...$args) Set the Twitter author. + * @method $this twitterTitle(?string $title = null, ...$args) Set the Twitter title. + * @method $this twitterDescription(?string $description = null, ...$args) Set the Twitter description. + * @method $this twitterImage(?string $url = null, ...$args) Set the Twitter cover image. */ class SEOManager { @@ -135,7 +135,7 @@ class SEOManager } /** Configure an extension. */ - public function extension(string $name, bool $enabled = true, string $view = null): static + public function extension(string $name, bool $enabled = true, ?string $view = null): static { $this->extensions[$name] = $enabled; @@ -159,7 +159,7 @@ class SEOManager } /** Configure or use Flipp. */ - public function flipp(string $alias, string|array $data = null): string|static + public function flipp(string $alias, string|array|null $data = null): string|static { if (is_string($data)) { $this->meta("flipp.templates.$alias", $data); @@ -185,7 +185,7 @@ class SEOManager } /** Configure or use Previewify. */ - public function previewify(string $alias, int|string|array $data = null): string|static + public function previewify(string $alias, int|string|array|null $data = null): string|static { if (is_string($data) || is_int($data)) { $this->meta("previewify.templates.$alias", (string) $data); @@ -250,7 +250,7 @@ class SEOManager } /** Add a head tag. */ - public function rawTag(string $key, string $tag = null): static + public function rawTag(string $key, ?string $tag = null): static { $tag ??= $key; @@ -275,7 +275,7 @@ class SEOManager * @param string|array|null $value The value (if a single key is provided). * @return $this|string|null */ - public function meta(string|array $key, string|array $value = null): mixed + public function meta(string|array $key, string|array|null $value = null): mixed { if (is_array($key)) { /** @var array $key */ diff --git a/src/helpers.php b/src/helpers.php index d891180..9ab7dd3 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -5,7 +5,7 @@ declare(strict_types=1); use ArchTech\SEO\SEOManager; if (! function_exists('seo')) { - function seo(string|array $key = null): SEOManager|string|array|null + function seo(string|array|null $key = null): SEOManager|string|array|null { if ($key === null) { return app('seo');