new script in bash
This commit is contained in:
parent
118b1ba33a
commit
93ba2a60f0
14
new.sh
Executable file
14
new.sh
Executable file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
content="---
|
||||
title:
|
||||
goal:
|
||||
role:
|
||||
date:
|
||||
z: 9999
|
||||
draft: true
|
||||
---
|
||||
"
|
||||
|
||||
echo "$content" > "./_content/$1.md"
|
||||
|
36
new.ts
36
new.ts
@ -1,36 +0,0 @@
|
||||
import { baseDir, getAllContent } from "$lib/content";
|
||||
import fs from "fs";
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
const path = args[0];
|
||||
|
||||
if (!path) {
|
||||
throw new Error("Path is needed!");
|
||||
}
|
||||
|
||||
const slug = path.split("/");
|
||||
const t = slug[slug.length - 1];
|
||||
|
||||
const nextZ =
|
||||
Math.max.apply(
|
||||
Math,
|
||||
getAllContent().map(c => Number(c.data.z)),
|
||||
) + 1;
|
||||
|
||||
const meta = (title: string = t, goal: string = "", role: string = "", date: string = "", z: number = nextZ) => `---
|
||||
title: ${title}
|
||||
goal: ${goal}
|
||||
role: ${role}
|
||||
date: ${date}
|
||||
z: ${z}
|
||||
draft: true
|
||||
---
|
||||
`;
|
||||
|
||||
const filePath = `${baseDir}${path}.md`;
|
||||
if (fs.existsSync(filePath)) {
|
||||
throw new Error("File already exists!");
|
||||
}
|
||||
|
||||
fs.writeFileSync(filePath, meta(), { flag: "w+" });
|
Loading…
Reference in New Issue
Block a user