From 45a3b3d41e3637f49b5bb200de66aebd0d5f0a2f Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 30 Mar 2023 20:27:12 +0900 Subject: feat(nuldoc): add `nuldoc new` command --- nuldoc-src/commands/new.ts | 92 ++++++++++++++++++++++++++++++++++++++++++++++ nuldoc-src/main.ts | 3 ++ 2 files changed, 95 insertions(+) create mode 100644 nuldoc-src/commands/new.ts (limited to 'nuldoc-src') diff --git a/nuldoc-src/commands/new.ts b/nuldoc-src/commands/new.ts new file mode 100644 index 0000000..2232997 --- /dev/null +++ b/nuldoc-src/commands/new.ts @@ -0,0 +1,92 @@ +import { dirname, join } from "std/path/mod.ts"; +import { ensureDir } from "std/fs/mod.ts"; +import { Config } from "../config.ts"; + +export async function runNewCommand(config: Config) { + const type = Deno.args[1]; + if (type !== "post" && type !== "slide") { + console.log(`Usage: nuldoc new + + must be either post or slide.`); + Deno.exit(1); + } + + const now = new Date(); + const ymd = `${now.getFullYear()}-${ + (now.getMonth() + 1).toString().padStart(2, "0") + }-${now.getDate().toString().padStart(2, "0")}`; + + const destFilePath = join( + Deno.cwd(), + config.locations.contentDir, + getDirPath(type), + ymd, + "TODO.xml", + ); + + await ensureDir(dirname(destFilePath)); + await Deno.writeTextFile(destFilePath, getTemplate(type, ymd)); + console.log( + `New file ${ + destFilePath.replace(Deno.cwd(), "") + } was successfully created.`, + ); +} + +function getDirPath(type: "post" | "slide"): string { + return type === "post" ? "posts" : "slides"; +} + +function getTemplate(type: "post" | "slide", date: string): string { + if (type === "post") { + return ` +
+ + TODO + + TODO + + + TODO + + + + ${date} + 公開 + + + +
+ TODO + + TODO + +
+
+`; + } else { + return ` + + + TODO + + TODO + + + TODO + + TODO + + TODO + + + + ${date} + 登壇 + + + + +`; + } +} diff --git a/nuldoc-src/main.ts b/nuldoc-src/main.ts index 1635d76..8598d80 100644 --- a/nuldoc-src/main.ts +++ b/nuldoc-src/main.ts @@ -1,4 +1,5 @@ import { runBuildCommand } from "./commands/build.ts"; +import { runNewCommand } from "./commands/new.ts"; import { runServeCommand } from "./commands/serve.ts"; import { config } from "./config.ts"; @@ -6,6 +7,8 @@ if (import.meta.main) { const command = Deno.args[0] ?? "build"; if (command === "build") { await runBuildCommand(config); + } else if (command === "new") { + runNewCommand(config); } else if (command === "serve") { runServeCommand(config); } else { -- cgit v1.2.3-70-g09d2