Skip to content

set custom favicon value & render #33

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions resources/views/components/extensions/favicon.blade.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}">
<link rel="icon" type="image/png" href="{{ asset('favicon.png') }}">
@if ($favicon = seo('favicon'))
<link rel="icon" href="{{ $favicon }}">
@else
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}">
<link rel="icon" type="image/png" href="{{ asset('favicon.png') }}">
@endif
8 changes: 6 additions & 2 deletions src/SEOManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,13 @@ public function previewify(string $alias, int|string|array $data = null): string
}

/** Enable favicon extension. */
public function favicon(): static
public function favicon(string|bool $value = true): static
{
$this->extensions['favicon'] = true;
if (is_string($value) && !empty($value)) {
$this->set('favicon', $value);
}

$this->extensions['favicon'] = !!$value;

return $this;
}
Expand Down
25 changes: 25 additions & 0 deletions tests/Pest/FaviconTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,28 @@
assertFileDoesNotExist(public_path('favicon.ico'));
assertFileDoesNotExist(public_path('favicon.png'));
});

test('it should have custom value with non-empty string', function () {
seo()->favicon('foo');

expect(seo('favicon'))->toBe('foo');
expect(meta())->toContain('<link rel="icon" href="foo">');
});

test('it should not have custom value with empty string or false', function () {
seo()->favicon('');

expect(seo('favicon'))->toBe(null);
expect(meta())->not()->toContain('link rel="icon"');

expect(seo('favicon'))->toBe(null);
expect(meta())->not()->toContain('link rel="icon"');
});

test('it should have default favicon setup', function () {
seo()->favicon();
expect(seo('favicon'))->toBe(null);

expect(meta())->toContain('<link rel="icon" type="image/x-icon" href="http://localhost/favicon.ico">');
expect(meta())->toContain('<link rel="icon" type="image/png" href="http://localhost/favicon.png">');
});