Kaan Barmore-Genç
cc876072c5
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
27 lines
726 B
JavaScript
27 lines
726 B
JavaScript
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);
|