From d470bfa5bb13d44ea799e332ecbaac8e493c4f2c Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Thu, 24 Sep 2026 18:49:06 +0200 Subject: properly support setting link prefix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Robert Günzler --- src/main.zig | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/main.zig b/src/main.zig index fcf2723..5988e75 100644 --- a/src/main.zig +++ b/src/main.zig @@ -26,6 +26,7 @@ pub fn main(init: std.process.Init) !void { // TODO: make this not a global var FORCE: bool = false; +var LINK_PREFIX: []const u8 = "/site"; const Cli = struct { const FlagSet = std.BufSet; @@ -121,6 +122,7 @@ const Cli = struct { fn run(init: std.process.Init) !void { if (init.environ_map.get("RBC_FORCE")) |_| FORCE = true; + if (init.environ_map.get("RBC_LINK_PREFIX")) |e| LINK_PREFIX = e; // parse options var opts = init.minimal.args.iterate(); @@ -478,9 +480,7 @@ const Builder = struct { index: ?std.ArrayList([]const u8) = null, pub const Options = struct { - // TODO: this is a bit of a hack no? we should just track the target - // path and use that - offset_from_siteroot: ?[]const u8 = "/site", + link_prefix: []const u8 = "/", }; const DELIM_START: []const u8 = "{["; @@ -500,6 +500,8 @@ const Builder = struct { .target_dir = target_dir, .options = options, }; + + b.options.link_prefix = LINK_PREFIX; return b; } @@ -671,13 +673,15 @@ const Builder = struct { \\ \\ @@ -750,7 +754,7 @@ const Builder = struct { const ref_name = try formatName(gpa, ref); defer gpa.free(ref_name); - const ref_link = try formatLink(gpa, ref, self.options.offset_from_siteroot); + const ref_link = try formatLink(gpa, ref, self.options.link_prefix); defer gpa.free(ref_link); try w.print( @@ -771,7 +775,7 @@ const Builder = struct { ref_name: []const u8, w: *std.Io.Writer, ) !void { - const link = try formatLink(gpa, ref_name, self.options.offset_from_siteroot); + const link = try formatLink(gpa, ref_name, self.options.link_prefix); defer gpa.free(link); try w.writeAll(link); } @@ -896,10 +900,10 @@ fn formatName(gpa: Allocator, name: []const u8) ![]u8 { return try std.mem.replaceOwned(u8, gpa, name, "_", " "); } -fn formatLink(gpa: Allocator, name: []const u8, pathPrefix: ?[]const u8) ![]u8 { +fn formatLink(gpa: Allocator, name: []const u8, prefix: []const u8) ![]u8 { const link_name = try std.fmt.allocPrint(gpa, "{s}.html", .{name}); defer gpa.free(link_name); - return try std.fs.path.join(gpa, &.{ pathPrefix orelse "/", link_name }); + return try std.fs.path.join(gpa, &.{ prefix, link_name }); } fn targetExists( -- cgit 1.4.1