/
new-note.ts
37 lines (30 loc) · 904 Bytes
/
new-note.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import * as readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";
import { writeFileSync } from "node:fs";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
import { exec } from "node:child_process";
const rl = readline.createInterface({ input, output });
const title = await rl.question("Title: ");
const content = `
---
layout: ../../layouts/MarkdownNoteLayout.astro
title: ${title}
publishedAt: ${new Date().toISOString().split("T").at(0)}
tags: []
draft: true
---
`.trim();
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const noteFileName = title.toLowerCase().replaceAll(" ", "-");
const noteFilePath = path.join(
__dirname,
"..",
"content",
"notes",
`${noteFileName}.md`
);
writeFileSync(noteFilePath, content);
exec(`code ${noteFilePath}`);
rl.close();