-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
28 lines (25 loc) · 934 Bytes
/
index.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
const path = require("path");
const data = require(path.resolve(process.cwd(), process.argv[2]));
const moment = require("moment");
const indentString = require('indent-string');
const toContext = (text) => {
if (/#[\d\w.-]+/.test(text)) {
return text.replace(/#([\d\w.-]+)/g, "@context($1)");
}
return "";
};
const convert = (item) => {
const title = item["Title"];
const content = String(item["Content"] || "").split("\n").map(line => {
return line.replace(/^-/, "")
}).join("\n");
const status = item["Status"];
const isCompleted = status === 2;
const date = item["Completed Time"];
const completedTag = date && isCompleted ? `@done(${moment(date).format("YYYY-MM-DD hh:mm")})` : "";
return `- ${title.trim()} ${toContext(title)} ${completedTag}
${indentString(content, 1, "\t")}
`;
};
const results = data.map(item => convert(item));
console.log(results.join("\n"));