const fs = require('fs'); const path = require('path'); const matter = require('gray-matter'); const locales = ['de', 'en']; function slugify(text) { return text.toLowerCase().replace(/\s+/g, '-'); } for (const locale of locales) { const dir = path.join('data', 'products', locale); const files = fs.readdirSync(dir).filter((f) => f.endsWith('.mdx')); for (const file of files) { const filePath = path.join(dir, file); const content = fs.readFileSync(filePath, 'utf8'); const { data } = matter(content); if (data.categories && data.categories.length > 0) { const category = slugify(data.categories[0]); const targetDir = path.join(dir, category); if (!fs.existsSync(targetDir)) { fs.mkdirSync(targetDir, { recursive: true }); } const targetPath = path.join(targetDir, file); fs.renameSync(filePath, targetPath); console.log(`Moved ${file} -> ${category}/`); } else { console.warn(`Warning: No category found for ${file}`); } } }