Skip to content

Commit fb36333

Browse files
committed
Add new post VS Code task
Convenient for creating a post with the current UTC timestamp
1 parent 59060c5 commit fb36333

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

.vscode/new-post.mjs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { writeFileSync } from "fs";
2+
import { join } from "path";
3+
4+
const [slug] = process.argv.slice(2);
5+
6+
if (!slug) {
7+
console.error("Usage: node new-post.mjs <post-slug>");
8+
process.exit(1);
9+
}
10+
11+
const now = new Date();
12+
const date = now.toISOString().replace(/\.\d{3}Z$/, "Z");
13+
14+
const filepath = join("src", "blog", `${slug}.md`);
15+
16+
const content = `---
17+
title:
18+
date: ${date}
19+
description:
20+
tags: []
21+
---
22+
`;
23+
24+
writeFileSync(filepath, content);
25+
console.log(`Created ${filepath}`);

.vscode/tasks.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,28 @@
66
"type": "promptString",
77
"description": "Post slug (e.g. my-post-title)"
88
},
9+
{
10+
"id": "newPostSlug",
11+
"type": "promptString",
12+
"description": "Post slug (e.g. my-post-title)"
13+
},
914
{
1015
"id": "authorName",
1116
"type": "promptString",
1217
"description": "Your name (e.g. John Doe)"
1318
}
1419
],
1520
"tasks": [
21+
{
22+
"label": "New Post",
23+
"type": "shell",
24+
"command": "node .vscode/new-post.mjs \"${input:newPostSlug}\"",
25+
"presentation": {
26+
"reveal": "always",
27+
"panel": "shared"
28+
},
29+
"problemMatcher": []
30+
},
1631
{
1732
"label": "New Comment",
1833
"type": "shell",

0 commit comments

Comments
 (0)