about summary refs log tree commit diff
path: root/src/main.zig
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2026-09-23 14:54:56 +0200
committerRobert Günzler <r@gnzler.io>2026-09-23 14:54:56 +0200
commitf7028d55a723c21bbe17714894b0704bc2720cc6 (patch)
tree48040aa7d399a64c4df2b853606da80cf128ced4 /src/main.zig
parent8a8397442d62550ffa4583e4d7ea635cc36a0b54 (diff)
downloadsite-f7028d55a723c21bbe17714894b0704bc2720cc6.tar.gz
implement serve command
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig
index b99f28c..60e40fe 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -87,6 +87,10 @@ const Cli = struct {
                 },
                 .handler = &Cli.gen,
             },
+            .{
+                .name = "serve",
+                .handler = &Cli.serve,
+            },
         },
         .handler = struct {
             fn inner(_: Io, _: Allocator, _: std.BufSet, _: [][]const u8) anyerror!void {
@@ -109,6 +113,9 @@ const Cli = struct {
             \\  gen ROOT-DIR TARGET-DIR
             \\    runs build for relevant files
             \\
+            \\  serve ROOT-DIR
+            \\    serves the site (using caddy)
+            \\
             \\
         , .{});
     }
@@ -249,6 +256,19 @@ const Cli = struct {
         try root_dir.access(io, "preproc.lua", .{}); // check preproc script
         try shell(io, pandoc_command, .{ .cwd = .{ .dir = root_dir } });
     }
+
+    fn serve(io: Io, _: Allocator, _: FlagSet, args: [][]const u8) !void {
+        if (args.len != 1) return Cli.usage();
+
+        const root_path = args[0];
+        const root_dir = try Io.Dir.cwd().openDir(io, root_path, .{});
+        defer root_dir.close(io);
+
+        log.info("srv : root={s}", .{root_path});
+        try shell(io,
+            \\caddy fmt --overwrite && caddy run --watch
+        , .{ .cwd = .{ .dir = root_dir } });
+    }
 };
 
 const File = struct {