Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: seo #15

Merged
merged 4 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"livewire",
"utilities",
"traits",
"concerns",
"helpers"
],
"homepage": "https://github.com/foxws/wireuse",
Expand All @@ -27,7 +28,6 @@
"illuminate/view": "^10.0|^11.0",
"laravel/scout": "^10.0|^11.0",
"livewire/livewire": "^3.4",
"artesaos/seotools": "^1.3",
"spatie/laravel-package-tools": "^1.16.5"
},
"require-dev": {
Expand All @@ -45,6 +45,7 @@
"spatie/php-structure-discoverer": "^2.1",
"spatie/laravel-html": "^3.11",
"spatie/laravel-model-states": "^2.7",
"artesaos/seotools": "^1.3",
"blade-ui-kit/blade-icons": "^1.6.0"
},
"autoload": {
Expand Down
4 changes: 2 additions & 2 deletions config/wireuse.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
|
| This extends Laravel HTML.
|
| @doc https://foxws.nl/posts/wireuse/laravel-html
| @doc https://foxws.nl/posts/wireuse-laravel-html-spatie
| @doc https://spatie.be/docs/laravel-html/v3
|
*/
Expand All @@ -41,7 +41,7 @@
|
| This controls structure discovery.
|
| @doc https://foxws.nl/posts/wireuse/structure-scout
| @doc https://foxws.nl/posts/wireuse-structure-scout
| @doc https://github.com/spatie/php-structure-discoverer
|
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Auth/Concerns/WithAuthorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public function bootWithAuthorization(): void

protected function authorizeAccess(): void
{
// $this->canViewAny(Todo::class);
// $this->canViewAny(Post::class);

// $this->canView($this->post);
}

protected function canViewAny(mixed $arguments): void
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Concerns/WithAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function clear(bool $submit = true): void

protected function keys(): array
{
return $this->request()->keys();
return array_keys($this->all());
}

protected function request(): FormRequest
Expand Down
12 changes: 12 additions & 0 deletions src/Forms/Concerns/WithSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ trait WithSession
{
protected static bool $store = false;

/**
* Restore the form data from the session.
* This should be called in your mount() method.
*/
public function restore(): void
{
if (! $this->useStore() || ! $this->hasStore()) {
Expand All @@ -18,6 +22,10 @@ public function restore(): void
);
}

/**
* Stores the form data in the session.
* This should be called in your updated() method.
*/
public function store(): void
{
if (! $this->useStore() || ! $this->storeWhen()) {
Expand All @@ -30,6 +38,10 @@ public function store(): void
session()->put($this->storeId(), serialize($this->storeWith()));
}

/**
* Forget the form data from the session.
* This may be called in your clear() method.
*/
public function forget(): void
{
session()->forget($this->storeId());
Expand Down
2 changes: 2 additions & 0 deletions src/Support/Html/Elements/Icon.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Icon extends BaseElement

public function svg(?string $name = null, ?string $class = null, ?array $attributes = []): static
{
throw_if(! function_exists('svg'), 'Make sure blade-ui-kit/blade-icons is installed');

return $this->html(svg($name, $class, $attributes)->toHtml());
}
}
12 changes: 6 additions & 6 deletions src/Support/Html/Mixins/LinkElementMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public function link(): mixed
$href = route($route, ...$parameters);

return $this
->attribute('wire:navigate')
->href($href)
->class([
'link',
'link-active' => request()->routeIs($route, "{$route}.*") || request()->fullUrlIs($href),
]);
->attributes([
'wire:navigate',
'wire:current' => 'link-active',
])
->class('link')
->href($href);
};
}

Expand Down
14 changes: 14 additions & 0 deletions src/Views/Concerns/WithSeo.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
trait WithSeo
{
public function bootWithSeo(): void
{
if (! $this->shouldSetSeoMeta()) {
return;
}

$this->setSeoMeta();
}

protected function setSeoMeta(): void
{
if (method_exists(static::class, 'getTitle')) {
SEOMeta::setTitle($this->getTitle());
Expand All @@ -20,4 +29,9 @@ public function bootWithSeo(): void
SEOMeta::setRobots($this->getRobots());
}
}

protected function shouldSetSeoMeta(): bool
{
return class_exists(SEOMeta::class);
}
}
4 changes: 2 additions & 2 deletions src/WireUseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function registerFeatures(): static
protected function registerStructureDiscovery(): static
{
if (! InstalledVersions::isInstalled('spatie/php-structure-discoverer')) {
abort(500, 'The spatie/php-structure-discoverer package is required to use the Structure Discovery.');
abort(500, 'The spatie/php-structure-discoverer package is required to use Structure Discovery.');
}

$this->app->singleton(ComponentScout::class, fn () => new ComponentScout);
Expand All @@ -64,7 +64,7 @@ protected function registerStructureDiscovery(): static
protected function registerHtmlMixins(): static
{
if (! InstalledVersions::isInstalled('spatie/laravel-html')) {
abort(500, 'The spatie/laravel-html package is required to use the HTML mixins.');
abort(500, 'The spatie/laravel-html package is required to use HTML mixins.');
}

$mixins = [
Expand Down