-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
56 lines (49 loc) · 1.38 KB
/
script.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function slugWriter(sentence, join = "") {
return sentence
.split(" ")
.map((w) => w.trim().toLowerCase())
.filter((w) => w.length > 1)
.join(join)
}
function fromCMD() {
let frontMatter = new Map()
frontMatter.set("title", "")
frontMatter.set("desc", "")
frontMatter.set("date", new Date(new Date() + new Date(1000*60*60*5.5)).toISOString())
frontMatter.set("tags", [])
const args = process.argv.slice(2)
for (let i = 0; i < args.length - 1; i += 2) {
const argK = args[i].slice(2)
if (!frontMatter.has(argK)) continue
if (argK === "tags") {
frontMatter.set(
argK,
args[i + 1].split(",").map((x) => slugWriter(x, ""))
)
continue
}
frontMatter.set(argK, args[i + 1])
}
return frontMatter
}
const frontMatter = fromCMD()
const fs = require("node:fs")
let tags = ""
for (let tag of frontMatter.get("tags")) {
tags += `- ${tag}`
if (tag !== frontMatter.get("tags").at(-1)) tags += `\n\t\t`
}
fs.writeFileSync(
`contents/posts/${slugWriter(frontMatter.get("title"), "-")}.liquid`,
`---
layout: 'post.liquid'
title: ${frontMatter.get("title")}
desc: ${frontMatter.get("desc")}
date: ${frontMatter.get("date")}
tags: [post,${frontMatter.get("tags").join(", ")}]
---
<article>
\t
</article>
`
)