Files
the-bias-times/src/app/api/articles/route.ts
hermes af11be82ac feat: public site homepage, search, and article reader
- Add editorial/magazine-style public layout with serif wordmark.
- Build homepage with three bias columns and editor's picks.
- Add search page with query, bias filter, and sort tabs.
- Add article detail page with summary, bias badge, and reasoning.
- Article cards include expandable "Why this classification?" panel.
- Style with warm, retro-editorial color palette and responsive layout.
2026-06-17 04:32:33 +00:00

37 lines
1.1 KiB
TypeScript

import { NextResponse } from 'next/server';
import { prisma } from '@/lib/db';
import { Bias } from '@prisma/client';
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const query = searchParams.get('q') || '';
const bias = searchParams.get('bias') as Bias | null;
const sort = searchParams.get('sort') || 'rank';
const limit = Number(searchParams.get('limit') || '50');
const offset = Number(searchParams.get('offset') || '0');
const orderBy = sort === 'date'
? { publishedAt: 'desc' as const }
: { rankScore: 'desc' as const };
const articles = await prisma.article.findMany({
where: {
status: 'PUBLISHED',
...(bias && { primaryBias: bias }),
...(query && {
OR: [
{ title: { contains: query } },
{ summary: { contains: query } },
{ topics: { contains: query } },
],
}),
},
orderBy: [orderBy, { publishedAt: 'desc' }],
take: limit,
skip: offset,
include: { source: true },
});
return NextResponse.json({ articles });
}