Skip to content

Commit

Permalink
Support for meta tag robots field (#32)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
valeriomonti and ralphjsmit authored Aug 30, 2024
1 parent 4e2f213 commit db0afcd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
'author' => 'Author name',
'image' => 'Image',
'characters' => 'Characters',
'robots' => 'Meta Tag Robots',
];
1 change: 1 addition & 0 deletions resources/lang/fr/translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
'author' => "Nom de l'auteur",
'image' => 'Image',
'characters' => 'Caractères',
'robots' => 'Balise meta Robots',
];
12 changes: 11 additions & 1 deletion src/SEO.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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([
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions tests/SEOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -27,6 +28,7 @@
'title' => e('Hello World – Google'),
'description' => e('Description – Google'),
'author' => e('Author – Google'),
'robots' => 'noindex, nofollow',
]);
});

Expand All @@ -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();

Expand All @@ -59,6 +62,7 @@
'title' => e('Hello World – Google'),
'description' => e('Description – Google'),
'author' => e('Author – Google'),
'robots' => 'noindex, nofollow',
]);
});

Expand All @@ -71,6 +75,7 @@
'title' => 'Hello World – Google',
'description' => 'Description – Google',
'author' => 'Author – Google',
'robots' => 'noindex, nofollow',
]);

EditPost::$SEOParameters = [];
Expand All @@ -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();

Expand All @@ -101,6 +108,7 @@
'title' => e('Hello World #2 – Google'),
'description' => null,
'author' => e('Author #2 – Google'),
'robots' => 'index, follow',
]);
});

Expand All @@ -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();

Expand All @@ -140,5 +149,6 @@
'title' => e('Hello World #3 – Google'),
'description' => e('Test #4'),
'author' => e('Author #3 – Google'),
'robots' => 'noindex, nofollow',
]);
});

0 comments on commit db0afcd

Please sign in to comment.