优化界面
This commit is contained in:
@@ -11,6 +11,7 @@ use App\Models\Category;
|
||||
use App\Models\Guide;
|
||||
use App\Support\MarkdownRenderer;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class NewsController extends Controller
|
||||
@@ -34,9 +35,27 @@ class NewsController extends Controller
|
||||
});
|
||||
}
|
||||
|
||||
$categories = Category::query()
|
||||
->where('type', 'news')
|
||||
->where('is_active', true)
|
||||
->withCount([
|
||||
'articles as published_articles_count' => fn (Builder $query): Builder => $query->published(),
|
||||
])
|
||||
->orderByDesc('published_articles_count')
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
$newsStats = [
|
||||
'total' => Article::query()->published()->count(),
|
||||
'today' => Article::query()->published()->whereDate('published_at', today())->count(),
|
||||
'high_source' => Article::query()->published()->where('source_level', 'high')->count(),
|
||||
'updated_7d' => Article::query()->published()->where('updated_at', '>=', now()->subDays(7))->count(),
|
||||
];
|
||||
|
||||
return view('public.news.index', [
|
||||
'items' => $builder->latest('published_at')->paginate(15)->withQueryString(),
|
||||
'categories' => Category::query()->where('type', 'news')->where('is_active', true)->orderBy('name')->get(),
|
||||
'categories' => $categories,
|
||||
'newsStats' => $newsStats,
|
||||
'filters' => $request->only(['q', 'category']),
|
||||
'sidebarModels' => AiModel::published()->orderByDesc('total_score')->limit(6)->get(),
|
||||
'sidebarGuides' => Guide::published()->latest('published_at')->limit(6)->get(),
|
||||
@@ -56,6 +75,8 @@ class NewsController extends Controller
|
||||
'item' => $article,
|
||||
'bodyHtml' => $this->markdownRenderer->render($article->body),
|
||||
'showRiskNotice' => $this->containsRiskKeyword($article->title.' '.$article->body),
|
||||
'sidebarModels' => AiModel::published()->orderByDesc('total_score')->limit(6)->get(),
|
||||
'sidebarGuides' => Guide::published()->latest('published_at')->limit(6)->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user