summaryrefslogtreecommitdiffhomepage
path: root/vhosts/blog/nuldoc-src
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-03-10 18:28:01 +0900
committernsfisis <nsfisis@gmail.com>2024-03-10 18:28:01 +0900
commitf7b12852fa8a6f557757dd3482c2b0b3f2aa4e45 (patch)
treeb905f3538257243c7bb4659d29e3079746bc8e89 /vhosts/blog/nuldoc-src
parent8fb9a93eb4d7ac8a7a8aa18c81922edc348d519c (diff)
downloadnsfisis.dev-f7b12852fa8a6f557757dd3482c2b0b3f2aa4e45.tar.gz
nsfisis.dev-f7b12852fa8a6f557757dd3482c2b0b3f2aa4e45.tar.zst
nsfisis.dev-f7b12852fa8a6f557757dd3482c2b0b3f2aa4e45.zip
feat(blog/nuldoc): add --date option to "new" command to change date in path
Diffstat (limited to 'vhosts/blog/nuldoc-src')
-rw-r--r--vhosts/blog/nuldoc-src/commands/new.ts28
1 files changed, 22 insertions, 6 deletions
diff --git a/vhosts/blog/nuldoc-src/commands/new.ts b/vhosts/blog/nuldoc-src/commands/new.ts
index db1faf72..19002531 100644
--- a/vhosts/blog/nuldoc-src/commands/new.ts
+++ b/vhosts/blog/nuldoc-src/commands/new.ts
@@ -1,20 +1,36 @@
import { dirname, join } from "std/path/mod.ts";
import { ensureDir } from "std/fs/mod.ts";
+import { parse } from "std/flags/mod.ts";
import { Config } from "../config.ts";
export async function runNewCommand(config: Config) {
- const type = Deno.args[1];
+ const parsedArgs = parse(Deno.args, {
+ string: ["date"],
+ });
+
+ const type = parsedArgs._[1];
if (type !== "post" && type !== "slide") {
console.log(`Usage: nuldoc new <type>
-<type> must be either post or slide.`);
+<type> must be either "post" or "slide".
+
+OPTIONS:
+ --date <DATE>
+`);
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 ymd = (() => {
+ if (parsedArgs.date) {
+ return parsedArgs.date;
+ }
+
+ const now = new Date();
+ const y = now.getFullYear();
+ const d = (now.getMonth() + 1).toString().padStart(2, "0");
+ const m = now.getDate().toString().padStart(2, "0");
+ return `${y}-${d}-${m}`;
+ })();
const destFilePath = join(
Deno.cwd(),