aboutsummaryrefslogtreecommitdiffhomepage
path: root/nuldoc-src
diff options
context:
space:
mode:
Diffstat (limited to 'nuldoc-src')
-rw-r--r--nuldoc-src/commands/build.ts (renamed from nuldoc-src/command.ts)50
-rw-r--r--nuldoc-src/commands/serve.ts22
-rw-r--r--nuldoc-src/main.ts12
3 files changed, 42 insertions, 42 deletions
diff --git a/nuldoc-src/command.ts b/nuldoc-src/commands/build.ts
index 57e4820..734f520 100644
--- a/nuldoc-src/command.ts
+++ b/nuldoc-src/commands/build.ts
@@ -1,28 +1,16 @@
import { dirname, join, joinGlobs } from "std/path/mod.ts";
import { ensureDir } from "std/fs/mod.ts";
import { expandGlob } from "std/fs/expand_glob.ts";
-import { serveDir } from "std/http/file_server.ts";
-import { serve } from "std/http/server.ts";
-import { Config } from "./config.ts";
-import { parseDocBookFile } from "./docbook/parse.ts";
-import { writeHtmlFile } from "./html.ts";
-import { Document } from "./docbook/document.ts";
-import convertPost from "./templates/post.ts";
-import convertPostList from "./templates/post_list.ts";
-import convertTag from "./templates/tag.ts";
-import generateAbout from "./templates/about.ts";
-
-export async function run(command: string, config: Config) {
- if (command === "build") {
- await cmdBuild(config);
- } else if (command === "serve") {
- cmdServe(config);
- } else {
- console.error(`Unknown command: ${command}`);
- }
-}
-
-async function cmdBuild(config: Config) {
+import { Config } from "../config.ts";
+import { parseDocBookFile } from "../docbook/parse.ts";
+import { writeHtmlFile } from "../html.ts";
+import { Document } from "../docbook/document.ts";
+import convertPost from "../templates/post.ts";
+import convertPostList from "../templates/post_list.ts";
+import convertTag from "../templates/tag.ts";
+import generateAbout from "../templates/about.ts";
+
+export async function runBuildCommand(config: Config) {
const posts = await generatePosts(config);
await generateTags(posts, config);
await generatePostList(posts, config);
@@ -30,24 +18,6 @@ async function cmdBuild(config: Config) {
await copyStaticFiles(config);
}
-function cmdServe(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,
- });
- });
-}
-
async function generatePosts(config: Config) {
const sourceDir = join(Deno.cwd(), config.locations.contentDir, "posts");
const postFiles = await collectPostFiles(sourceDir);
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,
+ });
+ });
+}
diff --git a/nuldoc-src/main.ts b/nuldoc-src/main.ts
index c7c175b..1635d76 100644
--- a/nuldoc-src/main.ts
+++ b/nuldoc-src/main.ts
@@ -1,6 +1,14 @@
+import { runBuildCommand } from "./commands/build.ts";
+import { runServeCommand } from "./commands/serve.ts";
import { config } from "./config.ts";
-import { run } from "./command.ts";
if (import.meta.main) {
- await run(Deno.args[0] ?? "build", config);
+ const command = Deno.args[0] ?? "build";
+ if (command === "build") {
+ await runBuildCommand(config);
+ } else if (command === "serve") {
+ runServeCommand(config);
+ } else {
+ console.error(`Unknown command: ${command}`);
+ }
}