feat(editor): add section manipulation APIs and interactive sidebar controls
All checks were successful
Production Build & Deploy / build-and-deploy (push) Successful in 1m3s

This commit is contained in:
Daniel S
2026-08-09 21:08:35 +02:00
parent d03750bc53
commit 0c073983e9
8 changed files with 387 additions and 854 deletions

View File

@@ -0,0 +1,82 @@
import type { APIRoute } from 'astro';
import fs from 'node:fs/promises';
import path from 'node:path';
export const prerender = false;
const DATA_DIR = process.env.DATA_DIR || path.join(process.cwd(), 'app', 'data');
// Vordefinierte Standard-Templates für neue Sektionen
const SECTION_TEMPLATES: Record<string, any> = {
HeroSection: {
type: 'HeroSection',
settings: {
title: 'Neue Überschrift',
subtitle: 'Beschreibungstext hier eingeben.',
cta_text: 'Jetzt anfragen',
cta_url: '#contact'
}
},
BentoGrid: {
type: 'BentoGrid',
settings: {
title: 'Unsere Highlights',
columns: 3,
items: [
{ title: 'Feature 1', description: 'Beschreibung 1' },
{ title: 'Feature 2', description: 'Beschreibung 2' },
{ title: 'Feature 3', description: 'Beschreibung 3' }
]
}
},
ContactSection: {
type: 'ContactSection',
settings: {
title: 'Kontaktieren Sie uns',
email_recipient: 'info@kunden-domain.de'
}
}
};
export const POST: APIRoute = async ({ request }) => {
try {
const { page_id, section_type } = await request.json();
if (!page_id || !section_type || !SECTION_TEMPLATES[section_type]) {
return new Response(JSON.stringify({ error: 'Gültige page_id und section_type erforderlich' }), { status: 400 });
}
const draftPath = path.join(DATA_DIR, 'site.config.draft.json');
const livePath = path.join(DATA_DIR, 'site.config.json');
let configRaw: string;
try {
configRaw = await fs.readFile(draftPath, 'utf-8');
} catch {
configRaw = await fs.readFile(livePath, 'utf-8');
}
const config = JSON.parse(configRaw);
const targetPage = config.pages?.find((p: any) => p.id === page_id);
if (!targetPage) {
return new Response(JSON.stringify({ error: 'Seite nicht gefunden' }), { status: 404 });
}
// Neue Sektion mit eindeutiger ID anfügen
const newSection = {
id: `sec_${section_type.toLowerCase()}_${Date.now()}`,
...SECTION_TEMPLATES[section_type]
};
targetPage.sections = targetPage.sections || [];
targetPage.sections.push(newSection);
await fs.mkdir(DATA_DIR, { recursive: true });
await fs.writeFile(draftPath, JSON.stringify(config, null, 2), 'utf-8');
return new Response(JSON.stringify({ success: true, section: newSection }), { status: 201 });
} catch (error) {
return new Response(JSON.stringify({ error: 'Fehler beim Hinzufügen der Sektion' }), { status: 500 });
}
};