commit b240f989055a80ad97b25555802ea4d6771e0382
Author: tri <tri@thac.loan>
Date:   Sun Sep 28 23:36:48 2025 +0700

    find readme file in each repo

diff --git a/src/git.zig b/src/git.zig
index 395bde7..f9fc639 100644
--- a/src/git.zig
+++ b/src/git.zig
@@ -36,7 +36,7 @@ pub const Commit = struct {
     time: []const u8,
 };
 
-pub fn getCommits(arena: std.mem.Allocator, dir: fs.Dir) ![]Commit {
+pub fn getCommits(arena: mem.Allocator, dir: fs.Dir) ![]Commit {
     const proc = try std.process.Child.run(.{
         .allocator = arena,
         .cwd_dir = dir,
@@ -66,3 +66,31 @@ pub fn getCommits(arena: std.mem.Allocator, dir: fs.Dir) ![]Commit {
     }
     return commits.items;
 }
+
+/// 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(.{
+        .allocator = arena,
+        .cwd_dir = dir,
+        // can't run git-ls-files on bare repos, so use git-ls-tree instead:
+        .argv = &.{ "git", "ls-tree", "--name-only", "HEAD" },
+    });
+
+    if (proc.stdout.len == 0) return null;
+
+    var filenames = std.mem.splitScalar(u8, proc.stdout, '\n');
+    while (filenames.next()) |name| {
+        if (name.len == 0) continue;
+        inline for (.{
+            "readme",
+            "readme.txt",
+            "readme.md",
+            "readme.markdown",
+        }) |matching_name| {
+            if (std.ascii.eqlIgnoreCase(name, matching_name)) {
+                return name;
+            }
+        }
+    }
+    return null;
+}
diff --git a/src/main.zig b/src/main.zig
index b793fd5..d6ddce8 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -72,7 +72,14 @@ pub fn main() !u8 {
             .last_commit_time = if (commits.len == 0) "" else try arena.dupe(u8, commits[0].time),
         });
 
-        try writeRepoPage(site_url, entry.name, target_dir, repo_dir, commits);
+        try writeRepoPage(
+            repo_arena,
+            site_url,
+            entry.name,
+            target_dir,
+            repo_dir,
+            commits,
+        );
 
         // TODO: write repo's commits
     }
@@ -177,6 +184,7 @@ pub fn writeHomePage(dir: fs.Dir, repos: []RepoSummary) !void {
 
 // TODO: write repo's index
 pub fn writeRepoPage(
+    arena: std.mem.Allocator,
     site_url: [*:0]const u8,
     repo_name: []const u8,
     target_dir: fs.Dir,
@@ -190,7 +198,10 @@ pub fn writeRepoPage(
     );
     defer out_repo_dir.close();
 
-    _ = in_repo_dir; // TODO: do I need this?
+    if (try git.findReadme(arena, in_repo_dir)) |readme_path| {
+        println("   {s}", .{readme_path});
+        // TODO write readme content to repo index page, probably in a <details>
+    }
 
     var file = try out_repo_dir.createFile("index.html", .{});
     defer file.close();