download patch
commit b30ac2cee8e567a06be95e55232b02d876f61c00
Author: tri <tri@thac.loan>
Date: Mon Sep 29 11:53:35 2025 +0700
show author name, implement html.escapeAlloc()
Author email is unused right now, but could be useful, idk.
diff --git a/src/git.zig b/src/git.zig
index 413f3f4..24ecc88 100644
--- a/src/git.zig
+++ b/src/git.zig
pub const Commit = struct {
hash: []const u8,
subject: []const u8,
time: []const u8,
+ author_email: []const u8,
+ author_name: []const u8,
};
pub fn getCommits(arena: mem.Allocator, dir: fs.Dir) ![]Commit {
pub fn getCommits(arena: mem.Allocator, dir: fs.Dir) ![]Commit {
"git",
"log",
"-z", // NUL byte is a safer delimiter than \n
- "--pretty=format:%H\n%ai\n%s",
+ "--pretty=format:%H\n%ai\n%s\n%ae\n%an",
},
// 512 MiB should be enough for everyone (tm)
.max_output_bytes = 1024 * 1024 * 512,
pub fn getCommits(arena: mem.Allocator, dir: fs.Dir) ![]Commit {
.hash = fields_iter.next().?,
.time = fields_iter.next().?,
.subject = fields_iter.next().?,
+ .author_email = fields_iter.next().?,
+ .author_name = fields_iter.next().?,
});
}
return commits.items;
diff --git a/src/html.zig b/src/html.zig
index ceaaa2e..3e0bd52 100644
--- a/src/html.zig
+++ b/src/html.zig
const std = @import("std");
const t = std.testing;
-pub fn escapeBuf(buf: *[]u8, text: []const u8) ![]const u8 {
- var w = std.Io.Writer.fixed(buf);
- try escape(&w, text);
- return w.buffered();
+pub fn escapeAlloc(arena: std.mem.Allocator, text: []const u8) ![]const u8 {
+ var w = std.Io.Writer.Allocating.init(arena);
+ try escape(&w.writer, text);
+ return w.written();
}
pub fn escape(out: *std.Io.Writer, text: []const u8) !void {
diff --git a/src/main.zig b/src/main.zig
index dd974eb..11ac632 100644
--- a/src/main.zig
+++ b/src/main.zig
pub fn writeRepoPage(args: RepoArgs) !void {
\\ <tr>
\\ <th>hash</th>
\\ <th>subject</th>
+ \\ <th>author</th>
\\ <th>time</th>
\\ </tr>
\\ </thead>
pub fn writeRepoPage(args: RepoArgs) !void {
\\
, .{});
- var escapeBuf: [1024]u8 = undefined;
for (commits) |cmt| {
- var escapeWriter = std.Io.Writer.fixed(&escapeBuf);
- try html.escape(&escapeWriter, cmt.subject[0..@min(cmt.subject.len, 80)]);
- const escaped_subject = escapeWriter.buffered();
+ const escaped_subject = try html.escapeAlloc(
+ arena,
+ cmt.subject[0..@min(cmt.subject.len, 80)],
+ );
+ const escaped_author = try html.escapeAlloc(arena, cmt.author_name);
try writer.interface.print(
\\<tr>
\\ <td class="monospace" title="commit diff coming Soon™">{0s}</td>
\\ <td>{1s}{2s}</td>
+ \\ <td>{4s}</td>
\\ <td><time class="relative" datetime="{3s}" title="{3s}">{3s}</time></td>
\\</tr>
\\
pub fn writeRepoPage(args: RepoArgs) !void {
escaped_subject,
if (cmt.subject.len > 80) "…" else "",
cmt.time,
+ escaped_author,
},
);
}