новости + переработка текстов
This commit is contained in:
@@ -26,6 +26,7 @@ trait BuildsPortalProps
|
||||
],
|
||||
'urls' => [
|
||||
'home' => route('landing.index'),
|
||||
'news' => route('news.index'),
|
||||
'login' => route('login'),
|
||||
'cabinet' => route('cabinet.index'),
|
||||
'admin' => route('admin.accounts.index'),
|
||||
|
||||
@@ -29,6 +29,8 @@ class LandingController extends Controller
|
||||
$rates = $realmConfig['rates'] ?? [];
|
||||
$user = Auth::user();
|
||||
$playersOnline = $accounts->onlinePlayerCount();
|
||||
$realmName = $this->canonicalMoonWellName($realmConfig['realm_name'] ?? null);
|
||||
$serverName = $this->canonicalMoonWellName($realmConfig['server_name'] ?? null);
|
||||
|
||||
$playUrl = $user !== null
|
||||
? route('cabinet.client')
|
||||
@@ -46,6 +48,7 @@ class LandingController extends Controller
|
||||
'tagType' => 'patch',
|
||||
'image_url' => $item->image_url,
|
||||
'featured' => $index === 0,
|
||||
'url' => route('news.show', $item),
|
||||
])
|
||||
->all();
|
||||
} catch (Throwable $exception) {
|
||||
@@ -56,7 +59,7 @@ class LandingController extends Controller
|
||||
|
||||
$bootstrap = [
|
||||
'realm' => [
|
||||
'name' => $realmConfig['realm_name'],
|
||||
'name' => $realmName,
|
||||
'mode' => sprintf('PvE · %s rate · RU', $rates['experience'] ?? 'x1'),
|
||||
'realmlist' => $realmConfig['realmlist'],
|
||||
'online' => $playersOnline !== null,
|
||||
@@ -67,10 +70,11 @@ class LandingController extends Controller
|
||||
'rates' => $rates,
|
||||
'client_version' => $realmConfig['client_version'] ?? '3.3.5a',
|
||||
'tagline' => $realmConfig['tagline'] ?? null,
|
||||
'server_name' => $realmConfig['server_name'] ?? 'MoonWell',
|
||||
'server_name' => $serverName,
|
||||
],
|
||||
'playUrl' => $playUrl,
|
||||
'posts' => $posts,
|
||||
'newsIndexUrl' => route('news.index'),
|
||||
'tweaks' => [
|
||||
'variant' => 'forest',
|
||||
'particles' => true,
|
||||
@@ -163,4 +167,13 @@ class LandingController extends Controller
|
||||
|
||||
return method_exists($bag, 'toArray') ? $bag->toArray() : [];
|
||||
}
|
||||
|
||||
private function canonicalMoonWellName(?string $name): string
|
||||
{
|
||||
if ($name === null || strcasecmp($name, 'MoonWell') === 0) {
|
||||
return 'MoonWell';
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Concerns\BuildsPortalProps;
|
||||
use App\Models\News;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class NewsController extends Controller
|
||||
{
|
||||
use BuildsPortalProps;
|
||||
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$articles = News::query()
|
||||
->published()
|
||||
->latest('created_at')
|
||||
->latest('id')
|
||||
->paginate(9)
|
||||
->withQueryString()
|
||||
->through(fn (News $item): array => $this->summary($item));
|
||||
|
||||
return Inertia::render('News/Index', [
|
||||
...$this->portalProps($request),
|
||||
'articles' => $articles,
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Request $request, News $news): Response
|
||||
{
|
||||
abort_unless($news->is_published, 404);
|
||||
|
||||
$moreNews = News::query()
|
||||
->published()
|
||||
->where('id', '!=', $news->id)
|
||||
->latest('created_at')
|
||||
->latest('id')
|
||||
->limit(3)
|
||||
->get()
|
||||
->map(fn (News $item): array => $this->summary($item))
|
||||
->values()
|
||||
->all();
|
||||
|
||||
return Inertia::render('News/Show', [
|
||||
...$this->portalProps($request),
|
||||
'article' => [
|
||||
...$this->summary($news),
|
||||
'body' => $news->body,
|
||||
'canonical_url' => route('news.show', $news),
|
||||
'back_url' => route('news.index'),
|
||||
],
|
||||
'moreNews' => $moreNews,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function summary(News $news): array
|
||||
{
|
||||
return [
|
||||
'id' => $news->id,
|
||||
'title' => $news->title,
|
||||
'excerpt' => Str::limit(trim(strip_tags($news->body)), 200),
|
||||
'date' => $news->created_at?->locale(app()->getLocale())->isoFormat('D MMMM YYYY'),
|
||||
'image_url' => $news->image_url,
|
||||
'url' => route('news.show', $news),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user