mirror of
https://github.com/archtechx/laravel-seo.git
synced 2025-12-12 09:54:03 +00:00
Merge remote-tracking branch 'origin/master' into fix/phpstan
This commit is contained in:
commit
6a48873d07
6 changed files with 66 additions and 1 deletions
12
README.md
12
README.md
|
|
@ -99,6 +99,18 @@ When a value is set specifically for Twitter, it will be prioritized over the ge
|
|||
seo()->twitterTitle('About us')
|
||||
```
|
||||
|
||||
### Favicons
|
||||
|
||||
By default, no favicon links will be included. You can manually enable the extension by calling:
|
||||
|
||||
```php
|
||||
seo()->favicon('path/to/logo.png');
|
||||
```
|
||||
|
||||
We'll generate a 32x32px `public/favicon.ico` & `public/favicon.png` icon. This should be sufficient for most cases.
|
||||
|
||||
**Please keep in mind that you need to install the [imagick](https://pecl.php.net/package/imagick) php extension and [intervention/image](http://image.intervention.io/) composer package.**
|
||||
|
||||
### Defaults
|
||||
|
||||
To configure default values, call the methods with the `default` argument:
|
||||
|
|
|
|||
2
assets/views/components/extensions/favicon.blade.php
Normal file
2
assets/views/components/extensions/favicon.blade.php
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}">
|
||||
<link rel="icon" type="image/png" href="{{ asset('favicon.png') }}">
|
||||
|
|
@ -31,7 +31,8 @@
|
|||
"orchestra/testbench": "^6.23",
|
||||
"nunomaduro/larastan": "^1.0",
|
||||
"pestphp/pest": "^1.2",
|
||||
"pestphp/pest-plugin-laravel": "^1.0"
|
||||
"pestphp/pest-plugin-laravel": "^1.0",
|
||||
"intervention/image": "^2.7"
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@ declare(strict_types=1);
|
|||
namespace ArchTech\SEO;
|
||||
|
||||
use Closure;
|
||||
use Exception;
|
||||
use Illuminate\Support\Str;
|
||||
use Intervention\Image\ImageManager;
|
||||
|
||||
/**
|
||||
* @method $this title(string $title = null, ...$args) Set the title.
|
||||
|
|
@ -179,6 +181,40 @@ class SEOManager
|
|||
return $this->set('image', "https://s.useflipp.com/{$template}.png?s={$signature}&v={$query}");
|
||||
}
|
||||
|
||||
/** Enable favicon extension. */
|
||||
public function favicon(string $path): static
|
||||
{
|
||||
if (! class_exists(ImageManager::class)) {
|
||||
throw new Exception('Intervention not available, please run `composer require intervention/image`');
|
||||
}
|
||||
|
||||
$this->extensions['favicon'] = true;
|
||||
|
||||
$doesntHaveFavicon = ! file_exists(public_path('favicon.ico'));
|
||||
$sourceIconDoesntExist = ! file_exists($path);
|
||||
|
||||
if ($sourceIconDoesntExist) {
|
||||
throw new Exception("Given icon path `{$path}` does not exist.");
|
||||
}
|
||||
|
||||
if ($doesntHaveFavicon) {
|
||||
// GD driver doesn't support .ico, that's why we use ImageMagick.
|
||||
$manager = new ImageManager(['driver' => 'imagick']);
|
||||
|
||||
$manager
|
||||
->make($path)
|
||||
->resize(32, 32)
|
||||
->save(public_path('favicon.ico'));
|
||||
|
||||
$manager
|
||||
->make($path)
|
||||
->resize(32, 32)
|
||||
->save(public_path('favicon.png'));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** Append canonical URL tags to the document head. */
|
||||
public function withUrl(): static
|
||||
{
|
||||
|
|
|
|||
14
tests/Pest/FaviconTest.php
Normal file
14
tests/Pest/FaviconTest.php
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
use function PHPUnit\Framework\assertFileExists;
|
||||
|
||||
test("it should throw an exception if the given source icon doesn't exist", function () {
|
||||
seo()->favicon('i-dont-exist.png');
|
||||
})->throws(Exception::class, 'Given icon path `i-dont-exist.png` does not exist.');
|
||||
|
||||
test('it should generate two favicons', function () {
|
||||
seo()->favicon(__DIR__ . '/../stubs/logo.png');
|
||||
|
||||
assertFileExists(public_path('favicon.ico'));
|
||||
assertFileExists(public_path('favicon.png'));
|
||||
});
|
||||
BIN
tests/stubs/logo.png
Normal file
BIN
tests/stubs/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
Loading…
Add table
Add a link
Reference in a new issue