mirror of
https://github.com/archtechx/laravel-seo.git
synced 2025-12-14 02:34:04 +00:00
Add Previewify image provider (#20)
* Add previewify image provider * feat: support for setting image with the @seo blade tag (resolves #22)
This commit is contained in:
parent
9ce6843879
commit
cf8ec8d3ae
6 changed files with 162 additions and 7 deletions
|
|
@ -181,6 +181,32 @@ class SEOManager
|
|||
return $this->set('image', "https://s.useflipp.com/{$template}.png?s={$signature}&v={$query}");
|
||||
}
|
||||
|
||||
/** Configure or use Previewify. */
|
||||
public function previewify(string $alias, int|string|array $data = null): string|static
|
||||
{
|
||||
if (is_string($data) || is_int($data)) {
|
||||
$this->meta("previewify.templates.$alias", (string) $data);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ($data === null) {
|
||||
$data = [
|
||||
'title' => $this->raw('title'),
|
||||
'description' => $this->raw('description'),
|
||||
];
|
||||
}
|
||||
|
||||
$query = base64_encode(json_encode($data, JSON_THROW_ON_ERROR));
|
||||
|
||||
/** @var string $template */
|
||||
$template = $this->meta("previewify.templates.$alias");
|
||||
|
||||
$signature = hash_hmac('sha256', $query, config('services.previewify.key'));
|
||||
|
||||
return $this->set('image', "https://previewify.app/generate/templates/{$template}/signed?signature={$signature}&fields={$query}");
|
||||
}
|
||||
|
||||
/** Enable favicon extension. */
|
||||
public function favicon(): static
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace ArchTech\SEO;
|
||||
|
||||
use ArchTech\SEO\Commands\GenerateFaviconsCommand;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use ImLiam\BladeHelper\BladeHelperServiceProvider;
|
||||
use ImLiam\BladeHelper\Facades\BladeHelper;
|
||||
|
|
@ -32,11 +33,11 @@ class SEOServiceProvider extends ServiceProvider
|
|||
], 'seo-views');
|
||||
|
||||
BladeHelper::directive('seo', function (...$args) {
|
||||
// Flipp supports more arguments
|
||||
if ($args[0] === 'flipp') {
|
||||
array_shift($args);
|
||||
// Flipp and Previewify support more arguments
|
||||
if (in_array($args[0], ['flipp', 'previewify'], true)) {
|
||||
$method = array_shift($args);
|
||||
|
||||
return seo()->flipp(...$args);
|
||||
return seo()->{$method}(...$args);
|
||||
}
|
||||
|
||||
// Two arguments indicate that we're setting a value, e.g. `@seo('title', 'foo')
|
||||
|
|
@ -46,7 +47,13 @@ class SEOServiceProvider extends ServiceProvider
|
|||
|
||||
// An array means we don't return anything, e.g. `@seo(['title' => 'foo'])
|
||||
if (is_array($args[0])) {
|
||||
seo($args[0]);
|
||||
foreach ($args[0] as $type => $value) {
|
||||
if (in_array($type, ['flipp', 'previewify'], true)) {
|
||||
seo()->{$type}(...Arr::wrap($value));
|
||||
} else {
|
||||
seo()->set($type, $value);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue