new script in bash

This commit is contained in:
Ivan Kirilov Dimitrov 2024-07-24 21:04:21 +02:00
parent 118b1ba33a
commit 93ba2a60f0
No known key found for this signature in database
GPG Key ID: 0BDAD4B211C49294
2 changed files with 14 additions and 36 deletions

14
new.sh Executable file
View 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
View File

@ -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+" });