#{index + 1} {sec.type}
+
@@ -104,6 +110,24 @@ const previewUrl = `${targetPage?.slug || '/'}?preview=draft`;
+
+
\ No newline at end of file
diff --git a/src/pages/api/editor/update-section-settings.ts b/src/pages/api/editor/update-section-settings.ts
new file mode 100644
index 0000000..eb1ff4e
--- /dev/null
+++ b/src/pages/api/editor/update-section-settings.ts
@@ -0,0 +1,49 @@
+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');
+
+export const POST: APIRoute = async ({ request }) => {
+ try {
+ const { page_id, section_id, settings } = await request.json();
+
+ if (!page_id || !section_id || !settings) {
+ return new Response(JSON.stringify({ error: 'page_id, section_id und settings 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 });
+ }
+
+ // Sektion finden und Einstellungen aktualisieren
+ const targetSection = targetPage.sections?.find((sec: any) => sec.id === section_id);
+ if (!targetSection) {
+ return new Response(JSON.stringify({ error: 'Sektion nicht gefunden' }), { status: 404 });
+ }
+
+ targetSection.settings = { ...targetSection.settings, ...settings };
+
+ 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, settings: targetSection.settings }), { status: 200 });
+ } catch (error) {
+ return new Response(JSON.stringify({ error: 'Fehler beim Aktualisieren der Sektions-Einstellungen' }), { status: 500 });
+ }
+};
diff --git a/tests/editorSections.test.ts b/tests/editorSections.test.ts
index a697196..da11a16 100644
--- a/tests/editorSections.test.ts
+++ b/tests/editorSections.test.ts
@@ -2,9 +2,10 @@ import { describe, it, expect, beforeEach } from 'vitest';
import fs from 'node:fs/promises';
import path from 'node:path';
-const DATA_DIR = process.env.DATA_DIR || path.join(process.cwd(), 'app', 'data');
+const DATA_DIR = path.join(process.cwd(), 'app', 'test_data_sections');
const draftPath = path.join(DATA_DIR, 'site.config.draft.json');
+
describe('Editor Sections API Test', () => {
beforeEach(async () => {
await fs.mkdir(DATA_DIR, { recursive: true });
diff --git a/tests/editorSettings.test.ts b/tests/editorSettings.test.ts
new file mode 100644
index 0000000..984499e
--- /dev/null
+++ b/tests/editorSettings.test.ts
@@ -0,0 +1,44 @@
+import { describe, it, expect, beforeEach } from 'vitest';
+import fs from 'node:fs/promises';
+import path from 'node:path';
+
+const DATA_DIR = path.join(process.cwd(), 'app', 'test_data_settings');
+const draftPath = path.join(DATA_DIR, 'site.config.draft.json');
+
+
+describe('Editor Property API Test', () => {
+ beforeEach(async () => {
+ await fs.mkdir(DATA_DIR, { recursive: true });
+ const dummyConfig = {
+ site_info: { title: 'Test Site', homepage_id: 'page_1' },
+ pages: [
+ {
+ id: 'page_1',
+ slug: '/',
+ title: 'Home',
+ sections: [
+ { id: 'sec_hero_123', type: 'HeroSection', settings: { title: 'Alter Titel', subtitle: 'Alt' } }
+ ]
+ }
+ ]
+ };
+ await fs.writeFile(draftPath, JSON.stringify(dummyConfig, null, 2), 'utf-8');
+ });
+
+ it('soll Sektions-Settings im Entwurf erfolgreich aktualisieren', async () => {
+ const raw = await fs.readFile(draftPath, 'utf-8');
+ const config = JSON.parse(raw);
+
+ const hero = config.pages[0].sections[0];
+ hero.settings.title = 'Neuer Hero Titel';
+ hero.settings.subtitle = 'Neuer Untertitel';
+
+ await fs.writeFile(draftPath, JSON.stringify(config, null, 2), 'utf-8');
+
+ const updatedRaw = await fs.readFile(draftPath, 'utf-8');
+ const updatedConfig = JSON.parse(updatedRaw);
+
+ expect(updatedConfig.pages[0].sections[0].settings.title).toBe('Neuer Hero Titel');
+ expect(updatedConfig.pages[0].sections[0].settings.subtitle).toBe('Neuer Untertitel');
+ });
+});