-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.js
More file actions
27 lines (22 loc) · 753 Bytes
/
generate.js
File metadata and controls
27 lines (22 loc) · 753 Bytes
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
/** @format */
import fs from 'node:fs';
import path from 'node:path';
import readline from 'node:readline';
import { fileURLToPath } from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.question('请输入文件名: \n', (name) => {
const post_path = path.join(__dirname, '../', 'source/_posts');
const template_path = path.join(post_path, 'template.md');
const target_path = path.join(post_path, `${name}.md`);
fs.copyFile(template_path, target_path, fs.constants.COPYFILE_EXCL, (err) => {
if (!err) {
console.log(`创建${name}.md成功!`);
}
rl.close();
});
});