zine/scripts/createPost.ts

45 lines
937 B
TypeScript

import fs from 'fs';
import path from 'path';
function genFileContents(dateISO: string, month: string, year: number) {
return `---
layout: '../../../layouts/Layout.astro'
date: '${dateISO}'
title: '${month} ${year}'
author: 'The exozyme community'
description: 'Description'
---
> Content
`;
}
const date = new Date(),
dateIso = date.toISOString(),
year = date.getFullYear(),
month = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
][date.getMonth()],
folderPath = path.join('./src/content/posts', year.toString());
if (!fs.existsSync(folderPath)) fs.mkdirSync(folderPath);
fs.writeFileSync(
path.join(folderPath, `${month.toLowerCase()}-${year}.md`),
genFileContents(dateIso, month, year),
'utf8'
);
console.log('Done!');