separating posts by its year in a subfolder
This commit is contained in:
parent
c4048c102b
commit
9f3c6a9534
|
@ -7,7 +7,7 @@ The monthly exozyme magazine.
|
|||
Its pretty easy! Clone this repo, create a new file at `src/content/posts/` with this command:
|
||||
|
||||
```sh
|
||||
bun run scripts/createPost.ts "Filename"
|
||||
bun run scripts/createPost.ts
|
||||
```
|
||||
|
||||
and then create a pull request!
|
||||
|
|
|
@ -1,33 +1,44 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const args = process.argv;
|
||||
|
||||
function genFileContents(filename: string, date: string) {
|
||||
function genFileContents(dateISO: string, month: string, year: number) {
|
||||
return `---
|
||||
layout: '../../layouts/Layout.astro'
|
||||
date: '${date}'
|
||||
title: 'Title'
|
||||
layout: '../../../layouts/Layout.astro'
|
||||
date: '${dateISO}'
|
||||
title: '${month} ${year}'
|
||||
author: 'The exozyme community'
|
||||
description: 'Description'
|
||||
slug: '${filename}'
|
||||
---
|
||||
|
||||
> Content
|
||||
`;
|
||||
}
|
||||
|
||||
if (args.length > 2) {
|
||||
const filename = args[2],
|
||||
date = new Date().toISOString();
|
||||
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('./src/content/posts', `${filename}.md`),
|
||||
genFileContents(filename, date),
|
||||
path.join(folderPath, `${month.toLowerCase()}-${year}.md`),
|
||||
genFileContents(dateIso, month, year),
|
||||
'utf8'
|
||||
);
|
||||
|
||||
console.log('Done!');
|
||||
} else {
|
||||
console.log('No filename provided.');
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
---
|
||||
layout: '../../layouts/Layout.astro'
|
||||
layout: '../../../layouts/Layout.astro'
|
||||
date: '2023-06-06T19:00:02Z'
|
||||
title: 'April 2023'
|
||||
author: 'The exozyme community'
|
||||
description: 'Stuff happened.'
|
||||
slug: 'april-2023'
|
||||
---
|
||||
|
||||
# April 2023
|
|
@ -1,10 +1,9 @@
|
|||
---
|
||||
layout: '../../layouts/Layout.astro'
|
||||
layout: '../../../layouts/Layout.astro'
|
||||
date: '2023-06-06T19:00:00Z'
|
||||
title: 'February 2023'
|
||||
author: 'The exozyme community'
|
||||
description: "So... exozine was supposed to be a monthly thing, but then I kinda forgot about it... oops. Well, don't worry, here's the February issue, only 4 months late!"
|
||||
slug: 'february-2023'
|
||||
---
|
||||
|
||||
# February 2023
|
|
@ -1,10 +1,9 @@
|
|||
---
|
||||
layout: '../../layouts/Layout.astro'
|
||||
layout: '../../../layouts/Layout.astro'
|
||||
date: '2023-01-29T00:00:00Z'
|
||||
title: 'January 2023'
|
||||
author: 'The exozyme community'
|
||||
description: 'Hi! This is the first issue of exozine, a monthly magazine about all the cool stuff that our exozyme community has been doing'
|
||||
slug: 'january-2023'
|
||||
---
|
||||
|
||||
# January 2023
|
|
@ -1,10 +1,9 @@
|
|||
---
|
||||
layout: '../../layouts/Layout.astro'
|
||||
layout: '../../../layouts/Layout.astro'
|
||||
date: '2023-06-28T17:00:00Z'
|
||||
title: 'June 2023'
|
||||
author: 'The exozyme community'
|
||||
description: 'Not very many blog posts this month, but we made some interesting websites!'
|
||||
slug: 'june-2023'
|
||||
---
|
||||
|
||||
# June 2023
|
|
@ -1,10 +1,9 @@
|
|||
---
|
||||
layout: '../../layouts/Layout.astro'
|
||||
layout: '../../../layouts/Layout.astro'
|
||||
date: '2023-06-06T19:00:01Z'
|
||||
title: 'March 2023'
|
||||
author: 'The exozyme community'
|
||||
description: "Here's the March issue of exozine, only 3 months late!"
|
||||
slug: 'march-2023'
|
||||
---
|
||||
|
||||
# March 2023
|
|
@ -1,10 +1,9 @@
|
|||
---
|
||||
layout: '../../layouts/Layout.astro'
|
||||
layout: '../../../layouts/Layout.astro'
|
||||
date: '2023-06-06T19:00:03Z'
|
||||
title: 'May 2023'
|
||||
author: 'The exozyme community'
|
||||
description: 'More stuff happened.'
|
||||
slug: 'may-2023'
|
||||
---
|
||||
|
||||
# May 2023
|
Loading…
Reference in a new issue