chore: commit remaining workspace changes
This commit is contained in:
@@ -59,9 +59,76 @@
|
||||
'per_page' => $posts->perPage(),
|
||||
'total' => $posts->total(),
|
||||
];
|
||||
|
||||
$makeForumAuthor = function ($user) {
|
||||
if (! $user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$name = trim((string) ($user->name ?? $user->username ?? ''));
|
||||
|
||||
if ($name === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$username = trim((string) ($user->username ?? ''));
|
||||
|
||||
return array_filter([
|
||||
'name' => $name,
|
||||
'url' => $username !== '' ? url('/@' . ltrim($username, '@')) : null,
|
||||
]);
|
||||
};
|
||||
|
||||
// Ensure we always provide a top-level author object for structured data.
|
||||
$topAuthor = $makeForumAuthor($author ?? $opPost?->user ?? null);
|
||||
if (! $topAuthor) {
|
||||
$topAuthor = ['name' => (string) ($opPost?->user?->name ?? $thread->user?->name ?? 'Skinbase')];
|
||||
}
|
||||
|
||||
$forumMicrodata = [
|
||||
'kind' => 'topic',
|
||||
'canonical' => route('forum.thread.show', ['thread' => $thread->id, 'slug' => $thread->slug]),
|
||||
'title' => (string) $thread->title,
|
||||
'text' => $threadDescription,
|
||||
'date_published' => $thread->created_at?->toIso8601String(),
|
||||
'date_modified' => ($thread->last_post_at ?? $thread->updated_at)?->toIso8601String(),
|
||||
'comment_count' => (int) ($reply_count ?? 0),
|
||||
'author' => $topAuthor,
|
||||
'comments' => collect([$opPost])
|
||||
->filter()
|
||||
->merge($posts->getCollection())
|
||||
->map(function ($post) use ($makeForumAuthor, $thread) {
|
||||
$rendered = (string) ForumPostContent::render((string) ($post->content ?? ''));
|
||||
$text = trim((string) preg_replace('/\s+/u', ' ', strip_tags(html_entity_decode($rendered, ENT_QUOTES | ENT_HTML5, 'UTF-8'))));
|
||||
|
||||
// If a post has no textual content, provide a short fallback so
|
||||
// the Comment structured data contains one of the required
|
||||
// representations (text/image/video). Prefer a simple label for
|
||||
// attachments or a generic reply placeholder.
|
||||
if ($text === '') {
|
||||
$hasAttachments = ! empty($post->attachments ?? null) && count($post->attachments ?? []) > 0;
|
||||
if ($hasAttachments) {
|
||||
$text = 'Attachment';
|
||||
} else {
|
||||
$text = 'Reply';
|
||||
}
|
||||
}
|
||||
|
||||
return array_filter([
|
||||
'url' => route('forum.thread.show', ['thread' => $post->thread_id, 'slug' => $thread->slug]) . '#post-' . $post->id,
|
||||
'text' => Str::limit($text, 300),
|
||||
'date_published' => $post->created_at?->toIso8601String(),
|
||||
'date_modified' => ($post->edited_at ?? $post->created_at)?->toIso8601String(),
|
||||
'author' => $makeForumAuthor($post->user ?? null) ?: ['name' => (string) ($post->user?->name ?? 'Skinbase')],
|
||||
], fn ($value) => $value !== null && $value !== '');
|
||||
})
|
||||
->values()
|
||||
->all(),
|
||||
];
|
||||
@endphp
|
||||
|
||||
@section('content')
|
||||
@include('partials.seo.forum-microdata', ['forumMicrodata' => $forumMicrodata])
|
||||
<div id="forum-thread-root"></div>
|
||||
@php
|
||||
$forumThreadProps = json_encode([
|
||||
@@ -76,7 +143,7 @@
|
||||
'created_at' => $thread->created_at?->toIso8601String(),
|
||||
],
|
||||
'category' => ['id' => $category->id ?? null, 'name' => $category->name ?? '', 'slug' => $category->slug ?? ''],
|
||||
'author' => ['name' => $author->name ?? 'Unknown'],
|
||||
'author' => ['name' => $author->name ?? 'Skinbase'],
|
||||
'opPost' => $serializedOp,
|
||||
'posts' => $serializedPosts,
|
||||
'pagination' => $paginationData,
|
||||
|
||||
Reference in New Issue
Block a user