Files
portfolio/scripts/seed-cms-content.js
denshooter c3f55c92ed feat: ultimate dynamic editorial overhaul
Automated CMS content seeding, integrated interactive AI Chat into Bento grid, implemented intelligent idle quote logic, and unified editorial styling across all sub-pages.
2026-02-16 01:18:34 +01:00

38 lines
1.3 KiB
JavaScript

#!/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 = 'POST', body = null) {
const res = await fetch(`${DIRECTUS_URL}/${endpoint}`, {
method,
headers: { 'Authorization': `Bearer ${DIRECTUS_TOKEN}`, 'Content-Type': 'application/json' },
body: body ? JSON.stringify(body) : null
});
return res.ok ? await res.json() : { error: true, status: res.status };
}
const seedData = [
{ key: 'hero.badge', de: 'Student & Self-Hoster', en: 'Student & Self-Hoster' },
{ key: 'hero.line1', de: 'Building', en: 'Building' },
{ key: 'hero.line2', de: 'Stuff.', en: 'Stuff.' },
{ key: 'about.quote.idle', de: 'Gerade am Planen des nächsten großen Projekts.', en: 'Currently planning the next big thing.' }
];
async function seedMessages() {
console.log('🌱 Befülle Directus mit Inhalten...');
for (const item of seedData) {
console.log(`- Erstelle Key: ${item.key}`);
const res = await api('items/messages', 'POST', {
key: item.key,
translations: [
{ languages_code: 'de-DE', value: item.de },
{ languages_code: 'en-US', value: item.en }
]
});
}
console.log('✅ CMS erfolgreich befüllt!');
}
seedMessages().catch(console.error);