From 61eaa6fbf4baa08778ebd8e4b34a9d9778e5e4fa Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 15 Dec 2021 00:49:49 +0100 Subject: [PATCH] Shorten page title in file view Move the more relevant sections of the page title earlier which make it possible to distinguish multiple tabs from each other when tab width is limited. --- routers/web/repo/view.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 5e9003b16baf4..5825e7203e657 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -141,6 +141,10 @@ func renderDirectory(ctx *context.Context, treeLink string) { return } + if ctx.Repo.TreePath != "" { + ctx.Data["Title"] = ctx.Tr("repo.file.title", ctx.Repo.Repository.Name+"/"+path.Base(ctx.Repo.TreePath), ctx.Repo.RefName) + } + // 3 for the extensions in exts[] in order // the last one is for a readme that doesn't // strictly match an extension @@ -374,7 +378,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st } defer dataRc.Close() - ctx.Data["Title"] = ctx.Data["Title"].(string) + " - " + ctx.Tr("repo.file.title", ctx.Repo.TreePath, ctx.Repo.RefName) + ctx.Data["Title"] = ctx.Tr("repo.file.title", ctx.Repo.Repository.Name+"/"+path.Base(ctx.Repo.TreePath), ctx.Repo.RefName) fileSize := blob.Size() ctx.Data["FileIsSymlink"] = entry.IsLink()