aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2023-03-15 01:57:11 +0900
committernsfisis <nsfisis@gmail.com>2023-03-15 02:14:35 +0900
commit229f35a2f498e0dd1a5760abc88176043a9af449 (patch)
treec3696b6603630a738fa885f22e28e38bc84b5755
parentcfc3f6027d063ea41b54dce5aea07e4af78b5bad (diff)
downloadblog.nsfisis.dev-229f35a2f498e0dd1a5760abc88176043a9af449.tar.gz
blog.nsfisis.dev-229f35a2f498e0dd1a5760abc88176043a9af449.tar.zst
blog.nsfisis.dev-229f35a2f498e0dd1a5760abc88176043a9af449.zip
feat(nuldoc): implement `serve` command
-rw-r--r--deno.lock30
-rwxr-xr-xnuldoc5
-rw-r--r--nuldoc-src/command.ts32
-rw-r--r--nuldoc-src/main.ts2
4 files changed, 65 insertions, 4 deletions
diff --git a/deno.lock b/deno.lock
index a1adf64..d9389f5 100644
--- a/deno.lock
+++ b/deno.lock
@@ -3,10 +3,23 @@
"remote": {
"https://deno.land/std@0.170.0/_util/asserts.ts": "d0844e9b62510f89ce1f9878b046f6a57bf88f208a10304aab50efcb48365272",
"https://deno.land/std@0.170.0/_util/os.ts": "8a33345f74990e627b9dfe2de9b040004b08ea5146c7c9e8fe9a29070d193934",
+ "https://deno.land/std@0.170.0/async/abortable.ts": "80b2ac399f142cc528f95a037a7d0e653296352d95c681e284533765961de409",
+ "https://deno.land/std@0.170.0/async/deadline.ts": "2c2deb53c7c28ca1dda7a3ad81e70508b1ebc25db52559de6b8636c9278fd41f",
+ "https://deno.land/std@0.170.0/async/debounce.ts": "60301ffb37e730cd2d6f9dadfd0ecb2a38857681bd7aaf6b0a106b06e5210a98",
+ "https://deno.land/std@0.170.0/async/deferred.ts": "77d3f84255c3627f1cc88699d8472b664d7635990d5358c4351623e098e917d6",
+ "https://deno.land/std@0.170.0/async/delay.ts": "5a9bfba8de38840308a7a33786a0155a7f6c1f7a859558ddcec5fe06e16daf57",
+ "https://deno.land/std@0.170.0/async/mod.ts": "7809ad4bb223e40f5fdc043e5c7ca04e0e25eed35c32c3c32e28697c553fa6d9",
+ "https://deno.land/std@0.170.0/async/mux_async_iterator.ts": "770a0ff26c59f8bbbda6b703a2235f04e379f73238e8d66a087edc68c2a2c35f",
+ "https://deno.land/std@0.170.0/async/pool.ts": "6854d8cd675a74c73391c82005cbbe4cc58183bddcd1fbbd7c2bcda42b61cf69",
+ "https://deno.land/std@0.170.0/async/retry.ts": "e8e5173623915bbc0ddc537698fa418cf875456c347eda1ed453528645b42e67",
+ "https://deno.land/std@0.170.0/async/tee.ts": "3a47cc4e9a940904fd4341f0224907e199121c80b831faa5ec2b054c6d2eff5e",
+ "https://deno.land/std@0.170.0/collections/_utils.ts": "fd759867be7a0047a1fa89ec89f7b58ebe3f2f7f089a8f4e416eb30c5d764868",
+ "https://deno.land/std@0.170.0/collections/deep_merge.ts": "0303cca7697646c5464ecb3337d494602056babae4f09baf6619f1043ba7eb6d",
"https://deno.land/std@0.170.0/crypto/_fnv/fnv32.ts": "aa9bddead8c6345087d3abd4ef35fb9655622afc333fc41fff382b36e64280b5",
"https://deno.land/std@0.170.0/crypto/_fnv/fnv64.ts": "625d7e7505b6cb2e9801b5fd6ed0a89256bac12b2bbb3e4664b85a88b0ec5bef",
"https://deno.land/std@0.170.0/crypto/_fnv/index.ts": "a8f6a361b4c6d54e5e89c16098f99b6962a1dd6ad1307dbc97fa1ecac5d7060a",
"https://deno.land/std@0.170.0/crypto/_fnv/util.ts": "4848313bed7f00f55be3cb080aa0583fc007812ba965b03e4009665bde614ce3",
+ "https://deno.land/std@0.170.0/crypto/_util.ts": "4a8cb74e7273d2400aa6da582ec58078cf8d54bc66530592048cbd7cc4152621",
"https://deno.land/std@0.170.0/crypto/_wasm/lib/deno_std_wasm_crypto.generated.mjs": "71c1ac20f32fdbdc9b31a14917779c7fa392dbc8b050059cbb2c35b400b975b1",
"https://deno.land/std@0.170.0/crypto/_wasm/mod.ts": "b49ec171049bbbaaed3c5a5a71dfcb3d09f880607c8d9c517638d0443bd0f874",
"https://deno.land/std@0.170.0/crypto/keystack.ts": "ee8ee58ca876f619cef56f40127405f77f9738f50a459b6ba44234b3a2cb6cc8",
@@ -16,6 +29,8 @@
"https://deno.land/std@0.170.0/encoding/base64.ts": "8605e018e49211efc767686f6f687827d7f5fd5217163e981d8d693105640d7a",
"https://deno.land/std@0.170.0/encoding/base64url.ts": "0283b12fcd306c11e3cf26fc022fecc800c6acc19704ea8bdb3908898fcd06d6",
"https://deno.land/std@0.170.0/encoding/hex.ts": "b51e99b684486a3ad2406807a8be953f5ef8bac95af202774a759f9fcf0d87a6",
+ "https://deno.land/std@0.170.0/flags/mod.ts": "4f50ec6383c02684db35de38b3ffb2cd5b9fcfcc0b1147055d1980c49e82521c",
+ "https://deno.land/std@0.170.0/fmt/colors.ts": "03ad95e543d2808bc43c17a3dd29d25b43d0f16287fe562a0be89bf632454a12",
"https://deno.land/std@0.170.0/fs/_util.ts": "fdc156f897197f261a1c096dcf8ff9267ed0ff42bd5b31f55053a4763a4bae3b",
"https://deno.land/std@0.170.0/fs/copy.ts": "c6303e52f544c81271c929931f5b59c9cfa4f81930719d2d3f777188c38aac9f",
"https://deno.land/std@0.170.0/fs/empty_dir.ts": "453d6232ff109f2afb5e57ec14c3228e399205c1b408d85536aed7230290c414",
@@ -29,6 +44,18 @@
"https://deno.land/std@0.170.0/fs/mod.ts": "79c209c6e66903b3426f9245a4f216380a0ed47ffe9d253f5a61a0bc9ad1f314",
"https://deno.land/std@0.170.0/fs/move.ts": "02ab1fc9b744da8b496f406e9fc77b0bf7960b6faaa7ec9f5fb0a129e5bef215",
"https://deno.land/std@0.170.0/fs/walk.ts": "677eac2e5386217a7a4e7526769ae28b41ff4ae7a3cd0389f3aa4eb662545edd",
+ "https://deno.land/std@0.170.0/http/file_server.ts": "c26eee517f9fe8a398556f3ba9a65accfa9a85af37e583ae537a4d5126a51dd7",
+ "https://deno.land/std@0.170.0/http/http_status.ts": "ed24048cc0d06066c944da59b0301da3ae2f990564bb4ad79bb52a09cf8e9b30",
+ "https://deno.land/std@0.170.0/http/server.ts": "1b93c76cd415d7b6ad0ae36c17ccb9149b23f4dff018f7d5aa1ab5c36637eb45",
+ "https://deno.land/std@0.170.0/http/util.ts": "759a2b57b44b722d2033d0dfe077f7e9a257f431db6d0319b78dcfebed0adb1e",
+ "https://deno.land/std@0.170.0/media_types/_db.ts": "981fb4a1ad1dad6bc896208e9d01929bea31b875b9a400ad145a5e802996b3ea",
+ "https://deno.land/std@0.170.0/media_types/_util.ts": "839abd68a8c67f89e3fd8900b89b8d4725368b488f72f067fcf8051e77e3a38d",
+ "https://deno.land/std@0.170.0/media_types/content_type.ts": "ecf5e4965195b7c19a0de7b251ae920cfb40897205c5529d829d357bf2218900",
+ "https://deno.land/std@0.170.0/media_types/format_media_type.ts": "e5f906e7b0509d47c81b3533ebb96783e57683cc0fcb03ea4e3420c641a80538",
+ "https://deno.land/std@0.170.0/media_types/get_charset.ts": "74aee42562808172c3ce2892a7e668f537bf565f2deebd2655a7d5c5b2779857",
+ "https://deno.land/std@0.170.0/media_types/parse_media_type.ts": "f40f0b98e7e6883bc2ea0f83482c48e2583a2a9785426dfc665f494f0ca3f17b",
+ "https://deno.land/std@0.170.0/media_types/type_by_extension.ts": "5bd760bb9518ba0cf4e40cc5b9d04dc84b0c562d9b04ac2cbd4050a4b47c9a6d",
+ "https://deno.land/std@0.170.0/media_types/vendor/mime-db.v1.52.0.ts": "724cee25fa40f1a52d3937d6b4fbbfdd7791ff55e1b7ac08d9319d5632c7f5af",
"https://deno.land/std@0.170.0/path/_constants.ts": "df1db3ffa6dd6d1252cc9617e5d72165cd2483df90e93833e13580687b6083c3",
"https://deno.land/std@0.170.0/path/_interface.ts": "ee3b431a336b80cf445441109d089b70d87d5e248f4f90ff906820889ecf8d09",
"https://deno.land/std@0.170.0/path/_util.ts": "d16be2a16e1204b65f9d0dfc54a9bc472cafe5f4a190b3c8471ec2016ccd1677",
@@ -37,6 +64,7 @@
"https://deno.land/std@0.170.0/path/mod.ts": "cf7cec7ac11b7048bb66af8ae03513e66595c279c65cfa12bfc07d9599608b78",
"https://deno.land/std@0.170.0/path/posix.ts": "b859684bc4d80edfd4cad0a82371b50c716330bed51143d6dcdbe59e6278b30c",
"https://deno.land/std@0.170.0/path/separator.ts": "fe1816cb765a8068afb3e8f13ad272351c85cbc739af56dacfc7d93d710fe0f9",
- "https://deno.land/std@0.170.0/path/win32.ts": "7cebd2bda6657371adc00061a1d23fdd87bcdf64b4843bb148b0b24c11b40f69"
+ "https://deno.land/std@0.170.0/path/win32.ts": "7cebd2bda6657371adc00061a1d23fdd87bcdf64b4843bb148b0b24c11b40f69",
+ "https://deno.land/std@0.170.0/version.ts": "eb6935c9beaac221b235d011ba5b127ceb5d3addf329cc01e05806af07ba93e1"
}
}
diff --git a/nuldoc b/nuldoc
index f27adab..a53edfd 100755
--- a/nuldoc
+++ b/nuldoc
@@ -5,4 +5,7 @@ base_dir="$(dirname "$BASH_SOURCE")"
deno run \
--allow-read="$base_dir" \
--allow-write="$base_dir/public" \
- "$base_dir/nuldoc-src/main.ts"
+ --allow-net="0.0.0.0:8000" \
+ --allow-run="./nuldoc" \
+ "$base_dir/nuldoc-src/main.ts" \
+ "$@"
diff --git a/nuldoc-src/command.ts b/nuldoc-src/command.ts
index dd15a77..d07f262 100644
--- a/nuldoc-src/command.ts
+++ b/nuldoc-src/command.ts
@@ -1,6 +1,8 @@
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";
@@ -9,13 +11,41 @@ import convertPost from "./templates/post.ts";
import convertPostList from "./templates/post_list.ts";
import convertTag from "./templates/tag.ts";
-export async function run(config: Config) {
+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) {
const posts = await generatePosts(config);
await generateTags(posts, config);
await generatePostList(posts, 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/main.ts b/nuldoc-src/main.ts
index 12a4ca9..c7c175b 100644
--- a/nuldoc-src/main.ts
+++ b/nuldoc-src/main.ts
@@ -2,5 +2,5 @@ import { config } from "./config.ts";
import { run } from "./command.ts";
if (import.meta.main) {
- await run(config);
+ await run(Deno.args[0] ?? "build", config);
}