auto create markdown file from parser interface
This commit is contained in:
1 parent
f143f1e511
commit
8434cf78ed
8 files changed
+2446
-866
No files matched your search
@@ -33,9 +33,10 @@ wss.on("connection", (ws) => {
|
||||
console.log(`Start ${q}`);
|
||||
|
||||
const md = loadMdFile(q);
|
||||
const q_stem = make_q_stem(q);
|
||||
|
||||
try {
|
||||
mkdirSync(joinPath(ROOT_DIR, md.q_stem));
|
||||
mkdirSync(joinPath(ROOT_DIR, q_stem));
|
||||
} catch (e) {}
|
||||
|
||||
let isChanged = false;
|
||||
@@ -63,7 +64,7 @@ wss.on("connection", (ws) => {
|
||||
const { min, sec } = m.groups;
|
||||
const t = `${min}_${sec}`;
|
||||
ts.push(t);
|
||||
newContent += `\n\n\n`;
|
||||
newContent += `\n\n\n`;
|
||||
isChanged = true;
|
||||
} else {
|
||||
newContent += `${line}\n`;
|
||||
@@ -80,10 +81,7 @@ wss.on("connection", (ws) => {
|
||||
case "timed_q":
|
||||
{
|
||||
const { q, t } = payload;
|
||||
const q_stem = q
|
||||
.replace(/\.[a-z0-9]+$/, "")
|
||||
.replace(/\[.+?\]/g, "")
|
||||
.trim();
|
||||
const q_stem = make_q_stem(q);
|
||||
filename = t ? joinPath(q_stem, `${t}.png`) : "";
|
||||
}
|
||||
break;
|
||||
@@ -92,7 +90,7 @@ wss.on("connection", (ws) => {
|
||||
const { q } = payload;
|
||||
const md = loadMdFile(q);
|
||||
|
||||
console.log(`Done timestamp ${q}`);
|
||||
console.log(`Done basic parsing ${q}`);
|
||||
|
||||
const { dedup } = md.data;
|
||||
if (dedup) {
|
||||
@@ -104,7 +102,7 @@ wss.on("connection", (ws) => {
|
||||
typeof dedup === "number" ? dedup : undefined,
|
||||
).then((stats) => {
|
||||
// Don't log a thing yet.
|
||||
console.log(`Done duduping ${md.filename}`);
|
||||
console.log(`Done deduping ${md.filename}`);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -125,16 +123,30 @@ wss.on("connection", (ws) => {
|
||||
* @returns
|
||||
*/
|
||||
function loadMdFile(q) {
|
||||
const q_stem = q
|
||||
.replace(/\.[a-z0-9]+$/, "")
|
||||
.replace(/\[.+?\]/g, "")
|
||||
.trim()
|
||||
.replace(/\s+/g, "_");
|
||||
const q_stem = make_q_stem(q);
|
||||
|
||||
try {
|
||||
mkdirSync(joinPath(ROOT_DIR, q_stem));
|
||||
} catch (e) {}
|
||||
|
||||
const filename = joinPath(ROOT_DIR, `${q_stem}.md`);
|
||||
return { q_stem, filename, ...matter(readFileSync(filename, "utf-8")) };
|
||||
try {
|
||||
// create a blank md file if not exists
|
||||
readFileSync(filename, { flag: "a" });
|
||||
} catch (e) {}
|
||||
|
||||
return { filename, ...matter(readFileSync(filename, "utf-8")) };
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} q
|
||||
* @returns
|
||||
*/
|
||||
function make_q_stem(q) {
|
||||
return q
|
||||
.replace(/\.[a-z0-9]+$/, "")
|
||||
.replace(/\[.+?\]/g, "")
|
||||
.trim()
|
||||
.replace(/\s+/g, "_");
|
||||
}
|
||||
Reference in new issue
Block a user