mirror of
https://github.com/archtechx/laravel-seo.git
synced 2025-12-12 09:54:03 +00:00
Add support for Favicons (#11)
* wip * wip * wip * Update tests/Pest/FaviconTest.php Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com> * Update tests/Pest/FaviconTest.php Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com> * Update README.md Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
This commit is contained in:
parent
1b2bfb2945
commit
5ca343a116
6 changed files with 66 additions and 1 deletions
|
|
@ -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.
|
||||
|
|
@ -176,6 +178,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
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue