Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.

Commit 1cb041d

Browse files
committed
SEO Directives
1 parent 72e66ed commit 1cb041d

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@extends('layout')
2+
3+
@section('content')
4+
5+
SEODirectives
6+
7+
@seoTitle('Custom Title')
8+
@seoDescription('Custom Description')
9+
@seoKeywords(['Custom', 'Keywords'])
10+
11+
@endsection

app/routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@
233233
})->name('rehydrateTwice');
234234

235235
Route::view('script', 'script')->name('script');
236+
Route::view('seoDirectives', 'seoDirectives')->name('seoDirectives');
236237

237238
Route::post('state', function () {
238239
Splade::share('info', 'This is invalid');

app/tests/Browser/HeadTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,16 @@ public function it_updates_the_head_when_modals_are_opened_and_closed()
6161
->assertTitle('Modal Base');
6262
});
6363
}
64+
65+
/** @test */
66+
public function it_has_blade_directives_to_set_the_seo()
67+
{
68+
$this->browse(function (Browser $browser) {
69+
$browser->visit('/seoDirectives')
70+
->waitForText('SEODirectives')
71+
->assertTitle('Custom Title')
72+
->assertMetaByName('description', 'Custom Description')
73+
->assertMetaByName('keywords', 'Custom, Keywords');
74+
});
75+
}
6476
}

config/splade.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
'component_prefix' => 'splade',
6565
'table_cell_directive' => 'cell',
6666
'escape_validation_messages' => true,
67+
'seo_title_directive' => 'seoTitle',
68+
'seo_description_directive' => 'seoDescription',
69+
'seo_keywords_directive' => 'seoKeywords',
6770
],
6871

6972
/**

src/Http/BladeDirectives.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function registerHandlers()
1919
Blade::directive('spladeHead', [$this, 'spladeHead']);
2020
Blade::directive('preserveScroll', [$this, 'preserveScroll']);
2121

22+
$this->registerSEODirectives();
2223
$this->registerTableCellDirective();
2324
}
2425

@@ -90,6 +91,26 @@ public static function parseTableCellDirectiveExpression(string $expression): ar
9091
return [$name, $function];
9192
}
9293

94+
/**
95+
* Registers the Blade SEO directives.
96+
*
97+
* @return void
98+
*/
99+
public function registerSEODirectives()
100+
{
101+
Blade::directive(config('splade.blade.seo_title_directive'), function ($expression) {
102+
return "<?php \ProtoneMedia\Splade\Facades\SEO::title($expression); ?>";
103+
});
104+
105+
Blade::directive(config('splade.blade.seo_description_directive'), function ($expression) {
106+
return "<?php \ProtoneMedia\Splade\Facades\SEO::description($expression); ?>";
107+
});
108+
109+
Blade::directive(config('splade.blade.seo_keywords_directive'), function ($expression) {
110+
return "<?php \ProtoneMedia\Splade\Facades\SEO::keywords($expression); ?>";
111+
});
112+
}
113+
93114
/**
94115
* Registers the Blade @cell directive.
95116
*

0 commit comments

Comments
 (0)