import { format, formatISO } from 'date-fns'; import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const title = process.argv[2] ?? 'New Blog Post'; let slug = title.toLowerCase().replaceAll(' ', '-'); while (slug.length > 60 && slug.includes('-')) { slug = slug.substring(0, slug.lastIndexOf('-')); } const filename = `${format(new Date(), 'yyyy.MM.dd')}.${slug}.md`; const contents = `--- title: '${title}' date: ${formatISO(new Date())} description: '' --- `; console.log('dirname', __dirname); console.log('filename', filename); fs.writeFileSync(path.join(__dirname, '..', 'src', 'routes', 'posts', filename), contents);