#!/usr/bin/env node require('dotenv').config(); const DIRECTUS_URL = process.env.DIRECTUS_URL || 'https://cms.dk0.dev'; const DIRECTUS_TOKEN = process.env.DIRECTUS_STATIC_TOKEN; async function api(endpoint, method = 'GET', body = null) { const url = `${DIRECTUS_URL}/${endpoint}`; const options = { method, headers: { 'Authorization': `Bearer ${DIRECTUS_TOKEN}`, 'Content-Type': 'application/json' } }; if (body) options.body = JSON.stringify(body); const response = await fetch(url, options); const data = await response.json(); return { ok: response.ok, data }; } async function perfectStructure() { console.log('💎 Optimiere CMS-Struktur zur Perfektion...'); // 1. Projekt-Buttons individualisieren console.log('1. Erweitere Projekte um individuelle Button-Labels...'); await api('fields/projects_translations', 'POST', { field: 'button_live_label', type: 'string', meta: { interface: 'input', options: { placeholder: 'z.B. Live Demo, App öffnen...' }, width: 'half' } }); await api('fields/projects_translations', 'POST', { field: 'button_github_label', type: 'string', meta: { interface: 'input', options: { placeholder: 'z.B. Source Code, GitHub...' }, width: 'half' } }); // 2. SEO für Inhaltsseiten console.log('2. Füge SEO-Felder zu Content-Pages hinzu...'); await api('fields/content_pages', 'POST', { field: 'meta_description', type: 'string', meta: { interface: 'input' } }); await api('fields/content_pages', 'POST', { field: 'keywords', type: 'string', meta: { interface: 'input' } }); // 3. Die ultimative "Messages" Collection (für UI Strings) console.log('3. Erstelle globale "Messages" Collection...'); await api('collections', 'POST', { collection: 'messages', schema: {}, meta: { icon: 'translate', display_template: '{{key}}' } }); await api('fields/messages', 'POST', { field: 'key', type: 'string', schema: { is_primary_key: true }, meta: { interface: 'input', options: { placeholder: 'home.hero.title' } } }); // Messages Translations await api('collections', 'POST', { collection: 'messages_translations', schema: {}, meta: { hidden: true } }); await api('fields/messages_translations', 'POST', { field: 'id', type: 'integer', schema: { is_primary_key: true, has_auto_increment: true }, meta: { hidden: true } }); await api('fields/messages_translations', 'POST', { field: 'messages_id', type: 'string', schema: {} }); await api('fields/messages_translations', 'POST', { field: 'languages_code', type: 'string', schema: {} }); await api('fields/messages_translations', 'POST', { field: 'value', type: 'text', meta: { interface: 'input' } }); // Relationen für Messages await api('relations', 'POST', { collection: 'messages_translations', field: 'messages_id', related_collection: 'messages', meta: { one_field: 'translations' } }); await api('relations', 'POST', { collection: 'messages_translations', field: 'languages_code', related_collection: 'languages' }); await api('fields/messages', 'POST', { field: 'translations', type: 'alias', meta: { interface: 'translations', special: ['translations'] } }); console.log('✨ CMS Struktur ist jetzt perfekt! Lade Directus neu.'); } perfectStructure().catch(console.error);