about summary refs log tree commit diff
path: root/src/gen.zig
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2025-09-10 13:38:16 +0200
committerRobert Günzler <r@gnzler.io>2025-09-29 17:06:10 +0200
commit109b73a3936c90aa89cd12c60aacf51439d31370 (patch)
tree77ec030f1676a9f8212b6f5eba2a70e74c99184c /src/gen.zig
parent34f08e9b1036171bbcd217929c7df2c7f16b627e (diff)
downloadsite-109b73a3936c90aa89cd12c60aacf51439d31370.tar.gz
use rbl for running pandoc
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to 'src/gen.zig')
-rw-r--r--src/gen.zig29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/gen.zig b/src/gen.zig
index ec26295..dbfb1ba 100644
--- a/src/gen.zig
+++ b/src/gen.zig
@@ -96,23 +96,24 @@ fn genSite(ctx: *Context) !void {
             try std.fs.cwd().makePath(dstdir);
         }
 
-        const f = try std.fs.cwd().createFile(dstpath, .{});
+        const f = try fs.FileSwapper.createAt(ctx.allocator(), dstpath);
+        defer f.close();
 
         const page_name = try std.mem.replaceOwned(u8, ctx.allocator(), dstname, "_", " ");
         defer ctx.allocator().free(page_name);
 
-        try build(ctx.allocator(), f, page_name, srcpath);
+        try build(ctx.allocator(), f.writer().any(), page_name, srcpath);
         ctx.generated += 1;
     }
 }
 
 // build a single html file
-fn build(allocator: std.mem.Allocator, f: std.fs.File, page_name: []const u8, srcpath: []const u8) !void {
+fn build(allocator: std.mem.Allocator, w: std.io.AnyWriter, page_name: []const u8, srcpath: []const u8) !void {
     const mtime = try fs.get_mtime(allocator, srcpath);
     defer allocator.free(mtime);
 
     // HEAD
-    try f.writer().print(
+    try w.print(
         \\<!-- Generated file, do not edit, you may edit and discard {[SOURCE]s} :) -->
         \\<!DOCTYPE html>
         \\<html lang="en">
@@ -138,30 +139,30 @@ fn build(allocator: std.mem.Allocator, f: std.fs.File, page_name: []const u8, sr
     });
 
     // NAV
-    try f.writer().writeAll(
+    try w.writeAll(
         \\<nav>
         \\
     );
-    portal(allocator, f.writer().any(), "meta.nav", false) catch {}; // ignore error
-    try f.writer().writeAll(
+    portal(allocator, w, "meta.nav", false) catch {}; // ignore error
+    try w.writeAll(
         \\</nav>
         \\</header>
         \\
     );
 
     // MAIN
-    try f.writer().print(
+    try w.print(
         \\<main>
         \\
     , .{});
-    try inject(allocator, f.writer().any(), srcpath);
-    try f.writer().writeAll(
+    try inject(allocator, w, srcpath);
+    try w.writeAll(
         \\</main>
         \\
     );
 
     // FOOTER
-    try f.writer().print(
+    try w.print(
         \\<footer>
         \\Edited on {[MTIME]s} <a href="{[SOURCE_URL]s}/{[PATH]s}" target="_blank">[src]</a>
         \\<a href="mailto:{[PUBLIC_INBOX]s}">[comments]</a>
@@ -183,12 +184,12 @@ fn build(allocator: std.mem.Allocator, f: std.fs.File, page_name: []const u8, sr
         .SOURCE_URL = Context.params.SOURCE_URL,
     });
 
-    try f.writer().writeAll(
+    try w.writeAll(
         \\<a href="#top">[&#9206;]</a>
         \\
     );
 
-    try f.writer().writeAll(
+    try w.writeAll(
         \\</body>
         \\</html>
         \\
@@ -221,7 +222,7 @@ fn meta(ctx: *Context, p: []const u8) !void {
         };
         defer ctx.allocator().free(link);
 
-        const f = try std.fs.cwd().createFile(dstpath, .{});
+        const f = try fs.FileSwapper.createAt(ctx.allocator(), dstpath);
         defer f.close();
 
         try f.writer().print(