diff options
| author | Robert Günzler <r@gnzler.io> | 2025-09-10 14:37:49 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2025-09-10 18:44:01 +0200 |
| commit | 5ca3ff505a36cd4bc23cd94ff0eef7475ef07d4d (patch) | |
| tree | b1bc39434a883f85ce26c95a285bf2944f45e478 /src | |
| parent | 0c1940ba525548cc8958733de55199cb9cfb974c (diff) | |
| download | site-5ca3ff505a36cd4bc23cd94ff0eef7475ef07d4d.tar.gz | |
support passing anchors through refs
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to 'src')
| -rw-r--r-- | src/gen.zig | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/gen.zig b/src/gen.zig index 3ea0bc2..6c7abcf 100644 --- a/src/gen.zig +++ b/src/gen.zig @@ -305,7 +305,7 @@ fn inject(allocator: std.mem.Allocator, w: std.io.AnyWriter, srcpath: []const u8 fn template(allocator: std.mem.Allocator, w: std.io.AnyWriter, refname: []const u8) anyerror!void { switch (refname[0]) { '/' => return try portal(allocator, w, refname[1..], false), - '@' => return try ref_link(allocator, w, refname[1..]), + '$' => return try ref_link(allocator, w, refname[1..]), '+' => return try ref_name(allocator, w, refname[1..]), else => return try ref(allocator, w, refname), } @@ -335,16 +335,19 @@ fn portal(allocator: std.mem.Allocator, w: std.io.AnyWriter, refname: []const u8 } fn ref(allocator: std.mem.Allocator, w: std.io.AnyWriter, refname: []const u8) anyerror!void { - const basename = try std.mem.replaceOwned(u8, allocator, refname, " ", "_"); + const endofref = std.mem.lastIndexOf(u8, refname, "#") orelse refname.len; + + const basename = try std.mem.replaceOwned(u8, allocator, refname[0..endofref], " ", "_"); defer allocator.free(basename); const refpathSite = try fs.join_path_and_filename(allocator, &.{Context.params.SITE_PATH}, &.{ basename, ".html" }); defer allocator.free(refpathSite); try w.print( - \\<a href="/{[PATH]s}">{[NAME]s}</a> + \\<a href="/{[PATH]s}{[anchor]s}">{[NAME]s}</a> , .{ - .NAME = refname, + .NAME = refname[0..endofref], .PATH = refpathSite, + .anchor = if (endofref < refname.len) refname[endofref..] else "", }); // XXX: track ref count? |