zine/scripts/createPost.ts

33 lines
638 B
TypeScript

import fs from 'fs';
import path from 'path';
const args = process.argv;
function genFileContents(filename: string, date: string) {
return `---
layout: '../../layouts/Layout.astro'
date: '${date}'
title: 'Title'
author: 'The exozyme community'
description: 'Description'
slug: '${filename}'
---
> Content
`;
}
if (args.length > 2) {
const filename = args[2],
date = new Date().toISOString();
fs.writeFileSync(
path.join('./src/content/posts', `${filename}.md`),
genFileContents(filename, date),
'utf8'
);
console.log('Done!');
} else {
console.log('No filename provided.');
}