feat(web/tree): show path and ref in page title

Amolith and Crush created

Display 'repo-name/path at ref | Project name' format in tree
view titles for better browser tab/history identification.
Shows shortened commit hash when viewing specific commits.

Implements: bug-45e898a
Co-authored-by: Crush <crush@charm.land>

Change summary

pkg/web/webui_tree.go | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

Detailed changes

pkg/web/webui_tree.go 🔗

@@ -77,12 +77,24 @@ func repoTree(w http.ResponseWriter, r *http.Request) {
 		repoDisplayName = repo.Name()
 	}
 
+	title := repo.Name()
+	if path != "." {
+		title += "/" + path
+	}
+	title += " at "
+	if isCommitHash && len(ref) > 7 {
+		title += ref[:7]
+	} else {
+		title += ref
+	}
+	title += " | " + repoDisplayName
+
 	data := TreeData{
 		RepoBaseData: RepoBaseData{
 			BaseData: BaseData{
 				ServerName: cfg.Name,
 				ActiveTab:  "tree",
-				Title:      "Files | " + repoDisplayName,
+				Title:      title,
 			},
 			Repo:          repo,
 			DefaultBranch: defaultBranch,