20 lines
726 B
JavaScript
20 lines
726 B
JavaScript
// Build-time search index (Astro static endpoint — no server, no dependencies).
|
|
// Kept lean: title/description/category/date/slug only (~60 KB for 200+ articles).
|
|
import { getCollection } from 'astro:content';
|
|
|
|
export async function GET() {
|
|
const posts = await getCollection('news', ({ data }) => !data.draft);
|
|
const index = posts
|
|
.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf())
|
|
.map((p) => ({
|
|
slug: p.id,
|
|
title: p.data.title,
|
|
description: p.data.description,
|
|
category: p.data.category,
|
|
date: p.data.date.toISOString().slice(0, 10),
|
|
}));
|
|
return new Response(JSON.stringify(index), {
|
|
headers: { 'Content-Type': 'application/json; charset=utf-8' },
|
|
});
|
|
}
|