feat: API contenuti taggati

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-05 17:18:30 +02:00
parent b5c0c107bc
commit eda4d73aac
7 changed files with 182 additions and 11 deletions
+28
View File
@@ -0,0 +1,28 @@
import type { APIRoute } from 'astro';
import { getDb } from '../../../../lib/db';
import { seedByTag } from '../../../../data/content-seed';
export const prerender = false;
const json = (status: number, body: object) =>
new Response(JSON.stringify(body), { status, headers: { 'Content-Type': 'application/json' } });
export const GET: APIRoute = () => {
const rows = getDb().prepare(
'SELECT tag, type, value, styles, updated_at, updated_by FROM content_blocks ORDER BY tag'
).all() as { tag: string; type: string; value: string; styles: string; updated_at: string; updated_by: string | null }[];
const items = rows.map((r) => {
let styles: Record<string, string> = {};
try { styles = JSON.parse(r.styles); } catch { /* styles corrotto: si ignora */ }
if (typeof styles !== 'object' || styles === null) styles = {};
return {
tag: r.tag,
type: r.type,
value: r.value,
styles,
styleOptions: seedByTag.get(r.tag)?.styleOptions ?? [],
updatedAt: r.updated_at,
updatedBy: r.updated_by,
};
});
return json(200, { items });
};