summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-06-22 02:29:49 +0900
committernsfisis <nsfisis@gmail.com>2024-06-22 02:29:49 +0900
commit9dc8ea25e802c2790441cb24a80dd4af01715df3 (patch)
tree6e5a2761eeb66a47ae2b05c53080b8dfb0301ce8
parent950f00a8d29b682919c654a696aeba8b576a36a6 (diff)
downloadnsfisis.dev-9dc8ea25e802c2790441cb24a80dd4af01715df3.tar.gz
nsfisis.dev-9dc8ea25e802c2790441cb24a80dd4af01715df3.tar.zst
nsfisis.dev-9dc8ea25e802c2790441cb24a80dd4af01715df3.zip
feat(blog/nuldoc): create config file, nuldoc.toml
-rw-r--r--vhosts/blog/deno.jsonc1
-rw-r--r--vhosts/blog/deno.lock15
-rw-r--r--vhosts/blog/nuldoc-src/config.ts87
-rw-r--r--vhosts/blog/nuldoc-src/main.ts4
-rw-r--r--vhosts/blog/nuldoc.toml47
5 files changed, 98 insertions, 56 deletions
diff --git a/vhosts/blog/deno.jsonc b/vhosts/blog/deno.jsonc
index 52b90be9..1751a80c 100644
--- a/vhosts/blog/deno.jsonc
+++ b/vhosts/blog/deno.jsonc
@@ -3,6 +3,7 @@
"checksum/": "https://deno.land/x/checksum@1.4.0/",
"highlight.js": "npm:highlight.js@11.9.0",
"std/": "https://deno.land/std@0.224.0/",
+ "zod/": "https://deno.land/x/zod@v3.23.8/",
},
"tasks": {
"check": "deno check nuldoc-src/main.ts && deno lint -- nuldoc-src/ && deno fmt --check -- nuldoc-src/",
diff --git a/vhosts/blog/deno.lock b/vhosts/blog/deno.lock
index b6528f25..714de503 100644
--- a/vhosts/blog/deno.lock
+++ b/vhosts/blog/deno.lock
@@ -150,7 +150,20 @@
"https://deno.land/x/checksum@1.4.0/hash.ts": "89ebbf7c57576e20462badc05bfb4a7ac01fe7668b6908cd547c79067c4221b9",
"https://deno.land/x/checksum@1.4.0/md5.ts": "1bb0889eaec838d5c1f219e0533277fe5ea10806d022920b6f0f2f8c398fec77",
"https://deno.land/x/checksum@1.4.0/mod.ts": "df8282cc1ecfd0f148535337c8bec077a1630e96a2012f2d19b2ca380f2c88c2",
- "https://deno.land/x/checksum@1.4.0/sha1.ts": "a608a6493694b7d734acfc4eee83e09bd9deaa4909cdac07f3eed3db427f97ae"
+ "https://deno.land/x/checksum@1.4.0/sha1.ts": "a608a6493694b7d734acfc4eee83e09bd9deaa4909cdac07f3eed3db427f97ae",
+ "https://deno.land/x/zod@v3.23.8/ZodError.ts": "528da200fbe995157b9ae91498b103c4ef482217a5c086249507ac850bd78f52",
+ "https://deno.land/x/zod@v3.23.8/errors.ts": "5285922d2be9700cc0c70c95e4858952b07ae193aa0224be3cbd5cd5567eabef",
+ "https://deno.land/x/zod@v3.23.8/external.ts": "a6cfbd61e9e097d5f42f8a7ed6f92f93f51ff927d29c9fbaec04f03cbce130fe",
+ "https://deno.land/x/zod@v3.23.8/helpers/enumUtil.ts": "54efc393cc9860e687d8b81ff52e980def00fa67377ad0bf8b3104f8a5bf698c",
+ "https://deno.land/x/zod@v3.23.8/helpers/errorUtil.ts": "7a77328240be7b847af6de9189963bd9f79cab32bbc61502a9db4fe6683e2ea7",
+ "https://deno.land/x/zod@v3.23.8/helpers/parseUtil.ts": "c14814d167cc286972b6e094df88d7d982572a08424b7cd50f862036b6fcaa77",
+ "https://deno.land/x/zod@v3.23.8/helpers/partialUtil.ts": "998c2fe79795257d4d1cf10361e74492f3b7d852f61057c7c08ac0a46488b7e7",
+ "https://deno.land/x/zod@v3.23.8/helpers/typeAliases.ts": "0fda31a063c6736fc3cf9090dd94865c811dfff4f3cb8707b932bf937c6f2c3e",
+ "https://deno.land/x/zod@v3.23.8/helpers/util.ts": "30c273131661ca5dc973f2cfb196fa23caf3a43e224cdde7a683b72e101a31fc",
+ "https://deno.land/x/zod@v3.23.8/index.ts": "d27aabd973613985574bc31f39e45cb5d856aa122ef094a9f38a463b8ef1a268",
+ "https://deno.land/x/zod@v3.23.8/locales/en.ts": "a7a25cd23563ccb5e0eed214d9b31846305ddbcdb9c5c8f508b108943366ab4c",
+ "https://deno.land/x/zod@v3.23.8/mod.ts": "ec6e2b1255c1a350b80188f97bd0a6bac45801bb46fc48f50b9763aa66046039",
+ "https://deno.land/x/zod@v3.23.8/types.ts": "1b172c90782b1eaa837100ebb6abd726d79d6c1ec336350c8e851e0fd706bf5c"
},
"workspace": {
"dependencies": [
diff --git a/vhosts/blog/nuldoc-src/config.ts b/vhosts/blog/nuldoc-src/config.ts
index d9cf0ec6..21a620a7 100644
--- a/vhosts/blog/nuldoc-src/config.ts
+++ b/vhosts/blog/nuldoc-src/config.ts
@@ -1,61 +1,40 @@
-export const config = {
- locations: {
- contentDir: "/content",
- destDir: "/public",
- staticDir: "/static",
- },
- rendering: {
- html: {
- indentWidth: 2,
- },
- },
- blog: {
- author: "nsfisis",
- fqdn: "blog.nsfisis.dev",
- siteName: "REPL: Rest-Eat-Program Loop",
- siteCopyrightYear: 2021,
- tagLabels: {
- "ci-cd": "CI/CD",
- "composer": "Composer",
- "conference": "カンファレンス",
- "cpp": "C++",
- "cpp17": "C++ 17",
- "gitlab": "GitLab",
- "isucon": "ISUCON",
- "neovim": "Neovim",
- "note-to-self": "備忘録",
- "ouj": "放送大学",
- "perl": "Perl",
- "php": "PHP",
- "phpcon-odawara": "PHP カンファレンス小田原",
- "phpconfuk": "PHP カンファレンス福岡",
- "phpconkagawa": "PHP カンファレンス香川",
- "phpconokinawa": "PHP カンファレンス沖縄",
- "phperkaigi": "PHPerKaigi",
- "phpkansai": "PHP カンファレンス関西",
- "phpstudy-tokyo": "PHP 勉強会@東京",
- "python": "Python",
- "python3": "Python 3",
- "ruby": "Ruby",
- "ruby3": "Ruby 3",
- "rust": "Rust",
- "scala": "Scala",
- "scalamatsuri": "ScalaMatsuri",
- "vim": "Vim",
- "wasm": "WebAssembly",
- "wireguard": "WireGuard",
- "ya8": "Ya8",
- "yapc": "YAPC",
- "zsh": "Zsh",
- },
- },
-};
+import { join } from "std/path/mod.ts";
+import { parse as parseToml } from "std/toml/mod.ts";
+import { z } from "zod/mod.ts";
-export type Config = typeof config;
+const ConfigSchema = z.object({
+ locations: z.object({
+ contentDir: z.string(),
+ destDir: z.string(),
+ staticDir: z.string(),
+ }),
+ rendering: z.object({
+ html: z.object({
+ indentWidth: z.number(),
+ }),
+ }),
+ blog: z.object({
+ author: z.string(),
+ fqdn: z.string(),
+ siteName: z.string(),
+ siteCopyrightYear: z.number(),
+ tagLabels: z.record(z.string(), z.string()),
+ }),
+});
+
+export type Config = z.infer<typeof ConfigSchema>;
export function getTagLabel(c: Config, slug: string): string {
if (!(slug in c.blog.tagLabels)) {
throw new Error(`Unknown tag: ${slug}`);
}
- return (c.blog.tagLabels as { [slug: string]: string })[slug];
+ return c.blog.tagLabels[slug];
+}
+
+export function getDefaultConfigPath(): string {
+ return join(Deno.cwd(), "nuldoc.toml");
+}
+
+export async function loadConfig(filePath: string): Promise<Config> {
+ return ConfigSchema.parse(parseToml(await Deno.readTextFile(filePath)));
}
diff --git a/vhosts/blog/nuldoc-src/main.ts b/vhosts/blog/nuldoc-src/main.ts
index 8598d80c..af6acc2e 100644
--- a/vhosts/blog/nuldoc-src/main.ts
+++ b/vhosts/blog/nuldoc-src/main.ts
@@ -1,7 +1,9 @@
import { runBuildCommand } from "./commands/build.ts";
import { runNewCommand } from "./commands/new.ts";
import { runServeCommand } from "./commands/serve.ts";
-import { config } from "./config.ts";
+import { getDefaultConfigPath, loadConfig } from "./config.ts";
+
+const config = await loadConfig(getDefaultConfigPath());
if (import.meta.main) {
const command = Deno.args[0] ?? "build";
diff --git a/vhosts/blog/nuldoc.toml b/vhosts/blog/nuldoc.toml
new file mode 100644
index 00000000..fcf211e0
--- /dev/null
+++ b/vhosts/blog/nuldoc.toml
@@ -0,0 +1,47 @@
+[locations]
+contentDir = "/content"
+destDir = "/public"
+staticDir = "/static"
+
+[rendering.html]
+indentWidth = 2
+
+[blog]
+author = "nsfisis"
+fqdn = "blog.nsfisis.dev"
+siteName = "REPL: Rest-Eat-Program Loop"
+siteCopyrightYear = 2021
+
+[blog.tagLabels]
+ci-cd = "CI/CD"
+composer = "Composer"
+conference = "カンファレンス"
+cpp = "C++"
+cpp17 = "C++ 17"
+gitlab = "GitLab"
+isucon = "ISUCON"
+neovim = "Neovim"
+note-to-self = "備忘録"
+ouj = "放送大学"
+perl = "Perl"
+php = "PHP"
+phpcon-odawara = "PHP カンファレンス小田原"
+phpconfuk = "PHP カンファレンス福岡"
+phpconkagawa = "PHP カンファレンス香川"
+phpconokinawa = "PHP カンファレンス沖縄"
+phperkaigi = "PHPerKaigi"
+phpkansai = "PHP カンファレンス関西"
+phpstudy-tokyo = "PHP 勉強会@東京"
+python = "Python"
+python3 = "Python 3"
+ruby = "Ruby"
+ruby3 = "Ruby 3"
+rust = "Rust"
+scala = "Scala"
+scalamatsuri = "ScalaMatsuri"
+vim = "Vim"
+wasm = "WebAssembly"
+wireguard = "WireGuard"
+ya8 = "Ya8"
+yapc = "YAPC"
+zsh = "Zsh"