From a20fc6ee101bcf2a626c4b538f1820ca11022d4a Mon Sep 17 00:00:00 2001
From: Runxi Yu <me@runxiyu.org>
Date: Mon, 10 Feb 2025 09:33:37 +0800
Subject: [PATCH] repo_index: Add anchors to filenames in the tree listing

---
 handle_repo_index.go      | 1 +
 templates/repo_index.html | 3 ++-

diff --git a/handle_repo_index.go b/handle_repo_index.go
index ea8aeba1869fdcdcf3a0815eff52792fe1f83ffd..23dd33443a22755ebd360797fd6d0b9a763c78dc 100644
--- a/handle_repo_index.go
+++ b/handle_repo_index.go
@@ -27,6 +27,7 @@ 	if err != nil {
 		w.Write([]byte("Error getting repo HEAD: " + err.Error()))
 		return
 	}
+	data["ref"] = head.Name().Short()
 	head_hash := head.Hash()
 	commit_iter, err := repo.Log(&git.LogOptions{From: head_hash})
 	if err != nil {
diff --git a/templates/repo_index.html b/templates/repo_index.html
index 866a0201af9dbaf76c8b9e3fad5d5e6863fce122..cf1326f76ec0a36f23a87232f89ce45b5fd3c2ca 100644
--- a/templates/repo_index.html
+++ b/templates/repo_index.html
@@ -42,10 +42,11 @@ <th scope="col">Size</th>
 </tr>
 </thead>
 <tbody>
+{{- $ref := .ref }}
 {{- range .files }}
 <tr>
 <td class="file-mode">{{ .Mode }}</td>
-<td class="file-name">{{ .Name }}</td>
+<td class="file-name"><a href="tree/{{ $ref }}/{{ .Name }}">{{ .Name }}</a></td>
 <td class="file-size">{{ .Size }}</td>
 </tr>
 {{- end }}

-- 
2.48.1