* feat: ship public site with SEO and visuals Publish CMS content on public routes with responsive media, accessibility checks, and deterministic visual baselines. Co-authored-by: Cursor <cursoragent@cursor.com> * fix: make browser visual CI deterministic for media Mount host public storage into FrankenPHP so seeded fixtures are served, and replace PNG-as-JPG fixtures with real JPEGs so Chromium can render them. Co-authored-by: Cursor <cursoragent@cursor.com> * fix: serve public media on same-origin storage paths Pest Browser hosts on 127.0.0.1:port while Storage::url used http://localhost, so screenshots captured broken images. Use relative /storage URLs for media and absolutize only OG tags via url(). Co-authored-by: Cursor <cursoragent@cursor.com> * test: refresh visual baselines from CI Ubuntu screenshots Media now loads on same-origin /storage paths, so baselines must capture the rendered fixtures. Use full-page snapshots from the CI runner to keep Pest's exact snapshot match stable across environments. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
104 lines
3.2 KiB
PHP
104 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Application\Data;
|
|
|
|
use App\Models\PortfolioCase;
|
|
use App\Models\SiteSetting;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
final readonly class PageMeta
|
|
{
|
|
/**
|
|
* @param array<string, mixed>|null $jsonLd
|
|
*/
|
|
public function __construct(
|
|
public string $title,
|
|
public string $description,
|
|
public string $canonical,
|
|
public string $ogType = 'website',
|
|
public ?string $ogImageUrl = null,
|
|
public ?string $ogImageAlt = null,
|
|
public ?array $jsonLd = null,
|
|
) {}
|
|
|
|
/**
|
|
* @param array<string, mixed>|null $jsonLd
|
|
*/
|
|
public static function forPage(
|
|
string $canonical,
|
|
SiteSetting $settings,
|
|
?string $title = null,
|
|
?string $description = null,
|
|
?string $ogImageUrl = null,
|
|
?string $ogImageAlt = null,
|
|
string $ogType = 'website',
|
|
?array $jsonLd = null,
|
|
): self {
|
|
return new self(
|
|
title: filled($title) ? (string) $title : self::defaultTitle($settings),
|
|
description: filled($description) ? (string) $description : self::defaultDescription($settings),
|
|
canonical: $canonical,
|
|
ogType: $ogType,
|
|
ogImageUrl: $ogImageUrl ?? self::defaultOgImageUrl($settings),
|
|
ogImageAlt: $ogImageAlt ?? $settings->default_og_image_alt,
|
|
jsonLd: $jsonLd,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed>|null $jsonLd
|
|
*/
|
|
public static function forCase(
|
|
PortfolioCase $case,
|
|
string $canonical,
|
|
SiteSetting $settings,
|
|
?array $jsonLd = null,
|
|
): self {
|
|
$title = filled($case->meta_title) ? (string) $case->meta_title : (string) $case->title;
|
|
$description = filled($case->meta_description)
|
|
? (string) $case->meta_description
|
|
: (filled($case->summary) ? (string) $case->summary : self::defaultDescription($settings));
|
|
|
|
$ogImageUrl = filled($case->cover_image_path)
|
|
? url(Storage::disk('public')->url((string) $case->cover_image_path))
|
|
: self::defaultOgImageUrl($settings);
|
|
|
|
$ogImageAlt = filled($case->cover_image_alt)
|
|
? (string) $case->cover_image_alt
|
|
: $settings->default_og_image_alt;
|
|
|
|
return new self(
|
|
title: $title,
|
|
description: $description,
|
|
canonical: $canonical,
|
|
ogType: 'article',
|
|
ogImageUrl: $ogImageUrl,
|
|
ogImageAlt: $ogImageAlt,
|
|
jsonLd: $jsonLd,
|
|
);
|
|
}
|
|
|
|
private static function defaultTitle(SiteSetting $settings): string
|
|
{
|
|
return filled($settings->default_meta_title)
|
|
? (string) $settings->default_meta_title
|
|
: (string) $settings->brand_name;
|
|
}
|
|
|
|
private static function defaultDescription(SiteSetting $settings): string
|
|
{
|
|
return (string) ($settings->default_meta_description ?? '');
|
|
}
|
|
|
|
private static function defaultOgImageUrl(SiteSetting $settings): ?string
|
|
{
|
|
if (! filled($settings->default_og_image_path)) {
|
|
return null;
|
|
}
|
|
|
|
return url(Storage::disk('public')->url((string) $settings->default_og_image_path));
|
|
}
|
|
}
|