From db0afcd2a1e320e032badb70940dce7aedacc373 Mon Sep 17 00:00:00 2001 From: Valerio Monti <97170623+valeriomonti@users.noreply.github.com> Date: Fri, 30 Aug 2024 12:38:24 +0200 Subject: [PATCH] Support for meta tag robots field (#32) * feat: add field to manage meta tag robots * feat: update tests with the robots data * Style * Update composer.json --------- Co-authored-by: Ralph J. Smit <59207045+ralphjsmit@users.noreply.github.com> --- composer.json | 2 +- resources/lang/en/translations.php | 1 + resources/lang/fr/translations.php | 1 + src/SEO.php | 12 +++++++++++- tests/SEOTest.php | 10 ++++++++++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index b1e7217..fdf3a65 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "php": "^8.0", "filament/filament": "^3.0", "illuminate/contracts": "^9.52|^10.0|^11.0", - "ralphjsmit/laravel-seo": "^1.0.4", + "ralphjsmit/laravel-seo": "^1.6.2", "spatie/laravel-package-tools": "^1.9.2" }, "require-dev": { diff --git a/resources/lang/en/translations.php b/resources/lang/en/translations.php index e5969a8..1a881bf 100644 --- a/resources/lang/en/translations.php +++ b/resources/lang/en/translations.php @@ -6,4 +6,5 @@ 'author' => 'Author name', 'image' => 'Image', 'characters' => 'Characters', + 'robots' => 'Meta Tag Robots', ]; diff --git a/resources/lang/fr/translations.php b/resources/lang/fr/translations.php index aec2e74..13f9787 100644 --- a/resources/lang/fr/translations.php +++ b/resources/lang/fr/translations.php @@ -6,4 +6,5 @@ 'author' => "Nom de l'auteur", 'image' => 'Image', 'characters' => 'Caractères', + 'robots' => 'Balise meta Robots', ]; diff --git a/src/SEO.php b/src/SEO.php index 2875b02..6b0ce57 100644 --- a/src/SEO.php +++ b/src/SEO.php @@ -3,6 +3,7 @@ namespace RalphJSmit\Filament\SEO; use Filament\Forms\Components\Group; +use Filament\Forms\Components\Select; use Filament\Forms\Components\Textarea; use Filament\Forms\Components\TextInput; use Illuminate\Database\Eloquent\Model; @@ -11,7 +12,7 @@ class SEO { - public static function make(array $only = ['title', 'author', 'description']): Group + public static function make(array $only = ['title', 'author', 'description', 'robots']): Group { return Group::make( Arr::only([ @@ -41,6 +42,15 @@ public static function make(array $only = ['title', 'author', 'description']): G }) ->reactive() ->columnSpan(2), + 'robots' => Select::make('robots') + ->label(__('filament-seo::translations.robots')) + ->options([ + 'index, follow' => 'Index, Follow', + 'index, nofollow' => 'Index, Nofollow', + 'noindex, follow' => 'Noindex, Follow', + 'noindex, nofollow' => 'Noindex, Nofollow', + ]), + ], $only) ) ->afterStateHydrated(function (Group $component, ?Model $record) use ($only): void { diff --git a/tests/SEOTest.php b/tests/SEOTest.php index d9edbe6..6b01712 100644 --- a/tests/SEOTest.php +++ b/tests/SEOTest.php @@ -16,6 +16,7 @@ ->set('data.seo.title', 'Hello World – Google') ->set('data.seo.description', 'Description – Google') ->set('data.seo.author', 'Author – Google') + ->set('data.seo.robots', 'noindex, nofollow') ->call('submitForm') ->assertHasNoErrors(); @@ -27,6 +28,7 @@ 'title' => e('Hello World – Google'), 'description' => e('Description – Google'), 'author' => e('Author – Google'), + 'robots' => 'noindex, nofollow', ]); }); @@ -48,6 +50,7 @@ ->set('data.seo.title', 'Hello World – Google') ->set('data.seo.description', 'Description – Google') ->set('data.seo.author', 'Author – Google') + ->set('data.seo.robots', 'noindex, nofollow') ->call('submitForm') ->assertHasNoErrors(); @@ -59,6 +62,7 @@ 'title' => e('Hello World – Google'), 'description' => e('Description – Google'), 'author' => e('Author – Google'), + 'robots' => 'noindex, nofollow', ]); }); @@ -71,6 +75,7 @@ 'title' => 'Hello World – Google', 'description' => 'Description – Google', 'author' => 'Author – Google', + 'robots' => 'noindex, nofollow', ]); EditPost::$SEOParameters = []; @@ -85,9 +90,11 @@ ->assertSet('data.seo.title', 'Hello World – Google') ->assertSet('data.seo.description', 'Description – Google') ->assertSet('data.seo.author', 'Author – Google') + ->assertSet('data.seo.robots', 'noindex, nofollow') ->set('data.seo.title', 'Hello World #2 – Google') ->set('data.seo.description', '') ->set('data.seo.author', 'Author #2 – Google') + ->set('data.seo.robots', 'index, follow') ->call('submitForm') ->assertHasNoErrors(); @@ -101,6 +108,7 @@ 'title' => e('Hello World #2 – Google'), 'description' => null, 'author' => e('Author #2 – Google'), + 'robots' => 'index, follow', ]); }); @@ -127,6 +135,7 @@ ->set('data.seo.title', 'Hello World #3 – Google') ->set('data.seo.description', 'Test #4') ->set('data.seo.author', 'Author #3 – Google') + ->set('data.seo.robots', 'noindex, nofollow') ->call('submitForm') ->assertHasNoErrors(); @@ -140,5 +149,6 @@ 'title' => e('Hello World #3 – Google'), 'description' => e('Test #4'), 'author' => e('Author #3 – Google'), + 'robots' => 'noindex, nofollow', ]); });