2024-01-24 22:28:20 +00:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
|
|
|
|
2024-01-26 02:21:07 +00:00
|
|
|
function genFileContents(dateISO: string, month: string, year: number) {
|
2024-01-24 22:28:20 +00:00
|
|
|
return `---
|
2024-01-26 02:21:07 +00:00
|
|
|
layout: '../../../layouts/Layout.astro'
|
|
|
|
date: '${dateISO}'
|
|
|
|
title: '${month} ${year}'
|
2024-01-24 22:28:20 +00:00
|
|
|
author: 'The exozyme community'
|
|
|
|
description: 'Description'
|
|
|
|
---
|
|
|
|
|
|
|
|
> Content
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2024-01-26 02:21:07 +00:00
|
|
|
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());
|
2024-01-24 22:28:20 +00:00
|
|
|
|
2024-01-26 02:21:07 +00:00
|
|
|
if (!fs.existsSync(folderPath)) fs.mkdirSync(folderPath);
|
2024-01-24 22:28:20 +00:00
|
|
|
|
2024-01-26 02:21:07 +00:00
|
|
|
fs.writeFileSync(
|
|
|
|
path.join(folderPath, `${month.toLowerCase()}-${year}.md`),
|
|
|
|
genFileContents(dateIso, month, year),
|
|
|
|
'utf8'
|
|
|
|
);
|
|
|
|
|
|
|
|
console.log('Done!');
|