-
Notifications
You must be signed in to change notification settings - Fork 1
/
permalink.js
39 lines (33 loc) · 935 Bytes
/
permalink.js
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
38
39
import { statSync } from "fs";
// 获取参数
const args = process.argv.slice(2);
// 日期的格式
function dateFormat(date) {
return `${date.getFullYear()}-${zero(date.getMonth() + 1)}-${zero(date.getDate())} ${zero(date.getHours())}:${zero(date.getMinutes())}:${zero(
date.getSeconds()
)}`;
}
// 小于10补0
function zero(d) {
return d.toString().padStart(2, "0");
}
// 获取文件创建时间
function getBirthtime() {
try {
const stats = statSync(args[0]);
const creationTime = stats.birthtime;
return dateFormat(creationTime);
} catch (err) {
console.error(err);
}
}
// 输出frontmatter
function outputFrontmatter() {
console.log("---");
console.log("title: ");
console.log("date: " + getBirthtime());
console.log("permalink: /pages/" + (Math.random() + Math.random()).toString(16).slice(2, 8) + "/");
console.log('excerpt: " "');
console.log("---");
}
outputFrontmatter();