feat: ship creator journey v2 and profile updates
This commit is contained in:
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Support\Seo;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
final class SeoDataBuilder
|
||||
@@ -66,13 +65,13 @@ final class SeoDataBuilder
|
||||
$builder->breadcrumbs($attributes['breadcrumbs']);
|
||||
}
|
||||
|
||||
foreach (Arr::wrap($attributes['json_ld'] ?? []) as $schema) {
|
||||
foreach (self::normalizeSchemaPayload($attributes['json_ld'] ?? []) as $schema) {
|
||||
$builder->addJsonLd($schema);
|
||||
}
|
||||
foreach (Arr::wrap($attributes['structured_data'] ?? []) as $schema) {
|
||||
foreach (self::normalizeSchemaPayload($attributes['structured_data'] ?? []) as $schema) {
|
||||
$builder->addJsonLd($schema);
|
||||
}
|
||||
foreach (Arr::wrap($attributes['faq_schema'] ?? []) as $schema) {
|
||||
foreach (self::normalizeSchemaPayload($attributes['faq_schema'] ?? []) as $schema) {
|
||||
$builder->addJsonLd($schema);
|
||||
}
|
||||
|
||||
@@ -271,6 +270,42 @@ final class SeoDataBuilder
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
private static function normalizeSchemaPayload(mixed $payload): array
|
||||
{
|
||||
if ($payload === null || $payload === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (is_string($payload)) {
|
||||
$decoded = json_decode($payload, true);
|
||||
|
||||
return json_last_error() === JSON_ERROR_NONE
|
||||
? self::normalizeSchemaPayload($decoded)
|
||||
: [];
|
||||
}
|
||||
|
||||
if (! is_array($payload)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($payload === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (! array_is_list($payload)) {
|
||||
return [$payload];
|
||||
}
|
||||
|
||||
return collect($payload)
|
||||
->map(static fn (mixed $schema): array => self::normalizeSchemaPayload($schema)[0] ?? [])
|
||||
->filter(static fn (array $schema): bool => $schema !== [])
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
private function clean(?string $value): ?string
|
||||
{
|
||||
$value = trim((string) $value);
|
||||
|
||||
Reference in New Issue
Block a user