aboutsummaryrefslogtreecommitdiffhomepage
path: root/nuldoc-src/commands/serve.ts
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2023-03-17 02:10:54 +0900
committernsfisis <nsfisis@gmail.com>2023-03-17 02:12:11 +0900
commit29bcdc6c1bad2240d404de9dca2463e46fdc1e93 (patch)
tree505e3004281013531a99327c83044852f20775fb /nuldoc-src/commands/serve.ts
parentcbfb56927c34a8d45c789fe463ab1b66b8d9d9ff (diff)
downloadblog.nsfisis.dev-29bcdc6c1bad2240d404de9dca2463e46fdc1e93.tar.gz
blog.nsfisis.dev-29bcdc6c1bad2240d404de9dca2463e46fdc1e93.tar.zst
blog.nsfisis.dev-29bcdc6c1bad2240d404de9dca2463e46fdc1e93.zip
refactor: split command.ts
Diffstat (limited to 'nuldoc-src/commands/serve.ts')
-rw-r--r--nuldoc-src/commands/serve.ts22
1 files changed, 22 insertions, 0 deletions
diff --git a/nuldoc-src/commands/serve.ts b/nuldoc-src/commands/serve.ts
new file mode 100644
index 0000000..b66ad2d
--- /dev/null
+++ b/nuldoc-src/commands/serve.ts
@@ -0,0 +1,22 @@
+import { join } from "std/path/mod.ts";
+import { serveDir } from "std/http/file_server.ts";
+import { serve } from "std/http/server.ts";
+import { Config } from "../config.ts";
+
+export function runServeCommand(config: Config) {
+ const rootDir = join(Deno.cwd(), config.locations.destDir);
+ serve(async (req) => {
+ const pathname = new URL(req.url).pathname;
+ if (!pathname.endsWith("css") && !pathname.endsWith("svg")) {
+ const p = Deno.run({
+ cmd: ["./nuldoc", "build"],
+ });
+ await p.status();
+ console.log("rebuild");
+ }
+ return serveDir(req, {
+ fsRoot: rootDir,
+ showIndex: true,
+ });
+ });
+}