Skip to content

Commit e8c03f5

Browse files
committed
更新脚本
1 parent fc8db96 commit e8c03f5

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"packageManager": "pnpm@9.15.1+sha512.1acb565e6193efbebda772702950469150cf12bcc764262e7587e71d19dc98a423dff9536e57ea44c49bdf790ff694e83c27be5faa23d67e0c033b583be4bfcf",
66
"repository": "https://github.com/ckvv/ckvv.github.io",
77
"scripts": {
8-
"gen": "node --experimental-strip-types ./scripts/gen.ts",
8+
"gen": "node ./scripts/gen.js",
99
"dev": "astro dev",
1010
"build": "astro build",
1111
"preview": "astro preview",

scripts/gen.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { access, constants, writeFile } from 'node:fs/promises';
2+
import { join } from 'node:path';
3+
import process from 'node:process';
4+
5+
const name = process.argv[2];
6+
7+
if (!name) {
8+
throw new Error('file name is required');
9+
}
10+
11+
const file = join(process.cwd(), 'content', `${name}.md`);
12+
13+
if (await isExist(file)) {
14+
throw new Error('file name is exist');
15+
}
16+
await writeFile(file, `---
17+
title: "${name}"
18+
tags: []
19+
date: "${formatDate(new Date())}"
20+
---
21+
22+
`);
23+
24+
async function isExist(file) {
25+
try {
26+
await access(file, constants.F_OK);
27+
return true;
28+
} catch (error) {
29+
return false;
30+
}
31+
}
32+
33+
function formatDate(date) {
34+
const [year, month, day] = [date.getFullYear(), date.getMonth(), date.getDay()];
35+
return {
36+
toString() {
37+
return `${year}/${`${month + 1}`.padStart(2, '0')}/${`${day + 1}`.padStart(2, '0')}`;
38+
},
39+
};
40+
}

scripts/gen.ts

-17
This file was deleted.

0 commit comments

Comments
 (0)