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-24 18:00:17 +0200
committerRobert Günzler <r@gnzler.io>2026-10-02 10:39:48 +0200
commit5f748385efffecf2e30ed5c70e2394cfac39a4b5 (patch)
tree77b5715b2870b0ce90d1f99771c20a953bef19eb /src/main.zig
parentd76cefb4fe1155ee8303328cdcff036e03fd9be9 (diff)
downloadsite-5f748385efffecf2e30ed5c70e2394cfac39a4b5.tar.gz
embed preproc.lua script
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '')
-rw-r--r--src/main.zig29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/main.zig b/src/main.zig
index 7b53295..c5956fc 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -785,6 +785,8 @@ const Builder = struct {
         log.debug("{s}: done", .{self.source.path});
     }
 
+    const prepocLua = @embedFile("preproc.lua");
+
     fn markdown(self: *Builder, io: Io, gpa: Allocator) !void {
         log.info("mdn : {s}", .{self.source.path});
 
@@ -800,12 +802,14 @@ const Builder = struct {
         });
         defer target_fd.close(io);
 
+        // embedded preproc.lua -> fd
+        // which we pass to the pandoc subshell
+        const fd = try memfd("preproc.lua", prepocLua);
         const pandoc_command = try std.fmt.allocPrint(gpa,
-            \\pandoc --from=markdown+wikilinks_title_after_pipe+autolink_bare_uris --to=html5 --lua-filter=../../preproc.lua --strip-comments --output={s} {s}
-        , .{ target_path, self.source.path });
+            \\pandoc --from=markdown+wikilinks_title_after_pipe+autolink_bare_uris --to=html5 --lua-filter=/dev/fd/{d} --strip-comments --output={s} {s}
+        , .{ fd, target_path, self.source.path });
         defer gpa.free(pandoc_command);
 
-        try self.root_dir.access(io, "../../preproc.lua", .{}); // check preproc script
         try shell(io, pandoc_command, .{ .cwd = .{ .dir = self.root_dir } });
 
         // track source
@@ -952,6 +956,25 @@ fn getXattrSourceComponents(gpa: Allocator, fd: Io.File) !?[][]const u8 {
 
 // shell
 
+pub fn memfd(name: [*:0]const u8, data: []const u8) !usize {
+    const fd = linux.memfd_create(name, 0);
+    if (linux.errno(fd) != .SUCCESS) return error.MemfdCreate;
+    const rc = linux.ftruncate(@intCast(fd), @intCast(data.len));
+    if (linux.errno(rc) != .SUCCESS) return error.Ftruncate;
+    const page = linux.mmap(
+        null,
+        data.len,
+        .{ .READ = true, .WRITE = true },
+        .{ .TYPE = .SHARED },
+        @intCast(fd),
+        0,
+    );
+    if (linux.errno(page) != .SUCCESS) return error.Mmap;
+    const ptr: [*]volatile u8 = @ptrFromInt(page);
+    @memcpy(ptr, data);
+    return fd;
+}
+
 pub fn shell(
     io: std.Io,
     command: []const u8,