download patch
commit 7bd7918ae997bf4e310897ec4dd401fd62898563
Author: tri <tri@thac.loan>
Date: Tue Sep 30 17:16:14 2025 +0700
implement getLatestCommit & accept repo arg
diff --git a/src/git.zig b/src/git.zig
index 24ecc88..e2bc7e7 100644
--- a/src/git.zig
+++ b/src/git.zig
pub fn getCommits(arena: mem.Allocator, dir: fs.Dir) ![]Commit {
return commits.items;
}
+pub fn getLatestCommit(arena: mem.Allocator, dir: fs.Dir) !?Commit {
+ const proc = try std.process.Child.run(.{
+ .allocator = arena,
+ .cwd_dir = dir,
+ .argv = &.{
+ "git",
+ "show",
+ "--summary",
+ "--pretty=format:%H\n%ai\n%s\n%ae\n%an",
+ },
+ .max_output_bytes = 4096,
+ });
+ const commit_text = proc.stdout;
+
+ if (commit_text.len == 0) {
+ return null;
+ }
+
+ var fields_iter = std.mem.splitSequence(u8, commit_text, "\n");
+ return Commit{
+ .hash = fields_iter.next().?,
+ .time = fields_iter.next().?,
+ .subject = fields_iter.next().?,
+ .author_email = fields_iter.next().?,
+ .author_name = fields_iter.next().?,
+ };
+}
+
/// If found, return the exact readme filename.
pub fn findReadme(arena: mem.Allocator, dir: fs.Dir) !?[]const u8 {
var proc = try std.process.Child.run(.{
diff --git a/src/main.zig b/src/main.zig
index 969bec1..228bb7e 100644
--- a/src/main.zig
+++ b/src/main.zig
const markdown = @import("markdown.zig");
const web_path = "_";
const assets_path = web_path ++ "/_khoe-hang";
+const Mode = union(enum) {
+ all: void,
+ single_repo: []const u8,
+};
+
pub fn main() !u8 {
- if (std.os.argv.len != 3) {
- println("Usage: khoe <dir> <site-url>", .{});
+ if (std.os.argv.len != 3 and std.os.argv.len != 4) {
+ println("Usage: khoe <dir> <site-url> [repo-name]", .{});
println(
\\For example:
\\ khoe /srv/git/repos https://khoe.thac.loan
- \\
+ \\ khoe /srv/git/repos https://khoe.thac.loan khoe.git
+ \\When repo-name is present, only the homepage and that repo are
+ \\regenerated.
, .{});
return 1;
}
const site_url = std.os.argv[2];
+ const mode: Mode =
+ if (std.os.argv.len == 3)
+ .all
+ else
+ .{ .single_repo = std.os.argv[3] };
+ _ = mode; // TODO
var dba_impl: std.heap.DebugAllocator(.{}) = .init;
defer _ = dba_impl.deinit();