aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2023-03-30 20:27:12 +0900
committernsfisis <nsfisis@gmail.com>2023-03-30 20:27:50 +0900
commit45a3b3d41e3637f49b5bb200de66aebd0d5f0a2f (patch)
treebfe40411a584f36ccce764f0f4bf305bb51fc6af
parentc01083ef9e8d2e30eac2e44855d5e08b8e775eab (diff)
downloadblog.nsfisis.dev-45a3b3d41e3637f49b5bb200de66aebd0d5f0a2f.tar.gz
blog.nsfisis.dev-45a3b3d41e3637f49b5bb200de66aebd0d5f0a2f.tar.zst
blog.nsfisis.dev-45a3b3d41e3637f49b5bb200de66aebd0d5f0a2f.zip
feat(nuldoc): add `nuldoc new` command
-rw-r--r--NOTE.md13
-rwxr-xr-xnuldoc2
-rw-r--r--nuldoc-src/commands/new.ts92
-rw-r--r--nuldoc-src/main.ts3
4 files changed, 106 insertions, 4 deletions
diff --git a/NOTE.md b/NOTE.md
index 12fec6a..099d014 100644
--- a/NOTE.md
+++ b/NOTE.md
@@ -5,16 +5,23 @@
Generate the site.
```
-$ ./nuldoc
+$ ./nuldoc build
```
Create a new post.
```
-$ mkdir -p content/posts/$(date +'%Y-%m-%d')
-$ touch content/posts/$(date +'%Y-%m-%d')/[TITLE].xml
+$ ./nuldoc new post
```
+Create a new slide.
+
+```
+$ ./nuldoc new slide
+```
+
+Update PDF.js.
+
```
$ curl -o static/pdf.min.js https://unpkg.com/pdfjs-dist@3.4.120/build/pdf.min.js
$ curl -o static/pdf.worker.min.js https://unpkg.com/pdfjs-dist@3.4.120/build/pdf.worker.min.js
diff --git a/nuldoc b/nuldoc
index a53edfd..7fc7cf2 100755
--- a/nuldoc
+++ b/nuldoc
@@ -4,7 +4,7 @@ base_dir="$(dirname "$BASH_SOURCE")"
deno run \
--allow-read="$base_dir" \
- --allow-write="$base_dir/public" \
+ --allow-write="$base_dir" \
--allow-net="0.0.0.0:8000" \
--allow-run="./nuldoc" \
"$base_dir/nuldoc-src/main.ts" \
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 <type>
+
+<type> 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 `<?xml version="1.0" encoding="UTF-8"?>
+<article xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0">
+ <info>
+ <title>TODO</title>
+ <abstract>
+ TODO
+ </abstract>
+ <keywordset>
+ <keyword>TODO</keyword>
+ </keywordset>
+ <revhistory>
+ <revision>
+ <date>${date}</date>
+ <revremark>公開</revremark>
+ </revision>
+ </revhistory>
+ </info>
+ <section xml:id="TODO">
+ <title>TODO</title>
+ <para>
+ TODO
+ </para>
+ </section>
+</article>
+`;
+ } else {
+ return `<?xml version="1.0" encoding="UTF-8"?>
+<slide>
+ <info>
+ <title>TODO</title>
+ <event>
+ TODO
+ </event>
+ <talktype>
+ TODO
+ </talktype>
+ <link>TODO</link>
+ <keywordset>
+ <keyword>TODO</keyword>
+ </keywordset>
+ <revhistory>
+ <revision>
+ <date>${date}</date>
+ <revremark>登壇</revremark>
+ </revision>
+ </revhistory>
+ </info>
+</slide>
+`;
+ }
+}
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 {