diff --git a/modules/web/middleware/data.go b/modules/web/middleware/data.go index a47da0f836b36..41fb1e7e6f64d 100644 --- a/modules/web/middleware/data.go +++ b/modules/web/middleware/data.go @@ -22,6 +22,8 @@ func GetContextData(c context.Context) reqctx.ContextData { func CommonTemplateContextData() reqctx.ContextData { return reqctx.ContextData{ + "PageTitleCommon": setting.AppName, + "IsLandingPageOrganizations": setting.LandingPageURL == setting.LandingPageOrganizations, "ShowRegistrationButton": setting.Service.ShowRegistrationButton, diff --git a/routers/web/repo/view_file.go b/routers/web/repo/view_file.go index 8bb9fb62a786e..ea3920439d426 100644 --- a/routers/web/repo/view_file.go +++ b/routers/web/repo/view_file.go @@ -172,7 +172,7 @@ func prepareFileView(ctx *context.Context, entry *git.TreeEntry) { blob := entry.Blob() - ctx.Data["Title"] = ctx.Tr("repo.file.title", ctx.Repo.Repository.Name+"/"+path.Base(ctx.Repo.TreePath), ctx.Repo.RefFullName.ShortName()) + ctx.Data["Title"] = ctx.Tr("repo.file.title", ctx.Repo.Repository.Name+"/"+ctx.Repo.TreePath, ctx.Repo.RefFullName.ShortName()) ctx.Data["FileIsSymlink"] = entry.IsLink() ctx.Data["FileTreePath"] = ctx.Repo.TreePath ctx.Data["RawFileLink"] = ctx.Repo.RepoLink + "/raw/" + ctx.Repo.RefTypeNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath) diff --git a/routers/web/repo/view_home.go b/routers/web/repo/view_home.go index 6b161df392c42..17043055e5ff9 100644 --- a/routers/web/repo/view_home.go +++ b/routers/web/repo/view_home.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "net/http" - "path" "strconv" "strings" "time" @@ -146,7 +145,7 @@ func prepareToRenderDirectory(ctx *context.Context) { if ctx.Repo.TreePath != "" { ctx.Data["HideRepoInfo"] = true - ctx.Data["Title"] = ctx.Tr("repo.file.title", ctx.Repo.Repository.Name+"/"+path.Base(ctx.Repo.TreePath), ctx.Repo.RefFullName.ShortName()) + ctx.Data["Title"] = ctx.Tr("repo.file.title", ctx.Repo.Repository.Name+"/"+ctx.Repo.TreePath, ctx.Repo.RefFullName.ShortName()) } subfolder, readmeFile, err := findReadmeFileInEntries(ctx, ctx.Repo.TreePath, entries, true) diff --git a/services/context/repo.go b/services/context/repo.go index 0ff1c7ea0337c..cfbfb33ab9ed1 100644 --- a/services/context/repo.go +++ b/services/context/repo.go @@ -537,6 +537,7 @@ func RepoAssignment(ctx *Context) { } ctx.Data["Title"] = repo.Owner.Name + "/" + repo.Name + ctx.Data["PageTitleCommon"] = repo.Name + " - " + setting.AppName ctx.Data["Repository"] = repo ctx.Data["Owner"] = ctx.Repo.Repository.Owner ctx.Data["CanWriteCode"] = ctx.Repo.CanWrite(unit_model.TypeCode) diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index 7aedd77445bc8..2a2109beac708 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -2,7 +2,7 @@ - {{if .Title}}{{.Title}} - {{end}}{{if .Repository.Name}}{{.Repository.Name}} - {{end}}{{AppName}} + {{if .Title}}{{.Title}} - {{end}}{{.PageTitleCommon}} {{if .ManifestData}}{{end}} diff --git a/templates/repo/view_content.tmpl b/templates/repo/view_content.tmpl index 3ba04a9974940..66e4fffcb9b19 100644 --- a/templates/repo/view_content.tmpl +++ b/templates/repo/view_content.tmpl @@ -1,5 +1,6 @@ {{$isTreePathRoot := not .TreeNames}} +
{{template "repo/sub_menu" .}}
diff --git a/web_src/js/components/ViewFileTreeStore.ts b/web_src/js/components/ViewFileTreeStore.ts index 0e16b566509a1..61d9168aa6c3a 100644 --- a/web_src/js/components/ViewFileTreeStore.ts +++ b/web_src/js/components/ViewFileTreeStore.ts @@ -25,9 +25,16 @@ export function createViewFileTreeStore(props: {repoLink: string, treePath: stri }, async loadViewContent(url: string) { - url = url.includes('?') ? url.replace('?', '?only_content=true') : `${url}?only_content=true`; - const response = await GET(url); - document.querySelector('.repo-view-content').innerHTML = await response.text(); + const u = new URL(url, window.origin); + u.searchParams.set('only_content', 'true'); + const response = await GET(u.href); + const elViewContent = document.querySelector('.repo-view-content'); + elViewContent.innerHTML = await response.text(); + const elViewContentData = elViewContent.querySelector('.repo-view-content-data'); + if (!elViewContentData) return; // if error occurs, there is no such element + const t1 = elViewContentData.getAttribute('data-document-title'); + const t2 = elViewContentData.getAttribute('data-document-title-common'); + document.title = `${t1} - ${t2}`; // follow the format in head.tmpl: ... }, async navigateTreeView(treePath: string) {