32 lines
1.1 KiB
PHP
32 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Category;
|
|
use App\Services\ArticleSelector;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
|
|
class FrontPageController extends Controller
|
|
{
|
|
public function __invoke(ArticleSelector $selector)
|
|
{
|
|
$categories = Category::whereNull('parent_id')->get()->map(function ($category) use ($selector) {
|
|
return [
|
|
'label' => $category->title,
|
|
'hero' => $category->slug === 'headlines', // or a boolean column on Category
|
|
'items' => $selector->forCategory($category)->map(fn ($article) => [
|
|
'source' => $article->feed->title ?? parse_url($article->feed->url, PHP_URL_HOST),
|
|
'time' => $article->published_at?->diffForHumans(),
|
|
'headline' => $article->title,
|
|
'deck' => \Illuminate\Support\Str::limit($article->description, 140),
|
|
'image' => $article->image_url,
|
|
'link' => $article->link,
|
|
]),
|
|
];
|
|
});
|
|
|
|
return Inertia::render('Index', ['categories' => $categories]);
|
|
}
|
|
}
|