Skip to content

Commit f9d69e5

Browse files
Merge branch 'main' into fix/35763-project-page-title
2 parents 1dbadfd + 39c08ce commit f9d69e5

File tree

7 files changed

+17
-7
lines changed

7 files changed

+17
-7
lines changed

modules/web/middleware/data.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ func GetContextData(c context.Context) reqctx.ContextData {
2222

2323
func CommonTemplateContextData() reqctx.ContextData {
2424
return reqctx.ContextData{
25+
"PageTitleCommon": setting.AppName,
26+
2527
"IsLandingPageOrganizations": setting.LandingPageURL == setting.LandingPageOrganizations,
2628

2729
"ShowRegistrationButton": setting.Service.ShowRegistrationButton,

routers/web/repo/view_file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func prepareFileView(ctx *context.Context, entry *git.TreeEntry) {
172172

173173
blob := entry.Blob()
174174

175-
ctx.Data["Title"] = ctx.Tr("repo.file.title", ctx.Repo.Repository.Name+"/"+path.Base(ctx.Repo.TreePath), ctx.Repo.RefFullName.ShortName())
175+
ctx.Data["Title"] = ctx.Tr("repo.file.title", ctx.Repo.Repository.Name+"/"+ctx.Repo.TreePath, ctx.Repo.RefFullName.ShortName())
176176
ctx.Data["FileIsSymlink"] = entry.IsLink()
177177
ctx.Data["FileTreePath"] = ctx.Repo.TreePath
178178
ctx.Data["RawFileLink"] = ctx.Repo.RepoLink + "/raw/" + ctx.Repo.RefTypeNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)

routers/web/repo/view_home.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"net/http"
10-
"path"
1110
"strconv"
1211
"strings"
1312
"time"
@@ -146,7 +145,7 @@ func prepareToRenderDirectory(ctx *context.Context) {
146145

147146
if ctx.Repo.TreePath != "" {
148147
ctx.Data["HideRepoInfo"] = true
149-
ctx.Data["Title"] = ctx.Tr("repo.file.title", ctx.Repo.Repository.Name+"/"+path.Base(ctx.Repo.TreePath), ctx.Repo.RefFullName.ShortName())
148+
ctx.Data["Title"] = ctx.Tr("repo.file.title", ctx.Repo.Repository.Name+"/"+ctx.Repo.TreePath, ctx.Repo.RefFullName.ShortName())
150149
}
151150

152151
subfolder, readmeFile, err := findReadmeFileInEntries(ctx, ctx.Repo.TreePath, entries, true)

services/context/repo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ func RepoAssignment(ctx *Context) {
537537
}
538538

539539
ctx.Data["Title"] = repo.Owner.Name + "/" + repo.Name
540+
ctx.Data["PageTitleCommon"] = repo.Name + " - " + setting.AppName
540541
ctx.Data["Repository"] = repo
541542
ctx.Data["Owner"] = ctx.Repo.Repository.Owner
542543
ctx.Data["CanWriteCode"] = ctx.Repo.CanWrite(unit_model.TypeCode)

templates/base/head.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="{{ctx.Locale.Lang}}" data-theme="{{ctx.CurrentWebTheme.InternalName}}">
33
<head>
44
<meta name="viewport" content="width=device-width, initial-scale=1">
5-
<title>{{if .Title}}{{.Title}} - {{end}}{{if .Repository.Name}}{{.Repository.Name}} - {{end}}{{AppName}}</title>
5+
<title>{{if .Title}}{{.Title}} - {{end}}{{.PageTitleCommon}}</title>
66
{{if .ManifestData}}<link rel="manifest" href="data:{{.ManifestData}}">{{end}}
77
<meta name="author" content="{{if .Repository}}{{.Owner.Name}}{{else}}{{MetaAuthor}}{{end}}">
88
<meta name="description" content="{{if .Repository}}{{.Repository.Name}}{{if .Repository.Description}} - {{.Repository.Description}}{{end}}{{else}}{{MetaDescription}}{{end}}">

templates/repo/view_content.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{{$isTreePathRoot := not .TreeNames}}
22

3+
<div class="repo-view-content-data tw-hidden" data-document-title="{{ctx.RootData.Title}}" data-document-title-common="{{ctx.RootData.PageTitleCommon}}"></div>
34
{{template "repo/sub_menu" .}}
45
<div class="repo-button-row">
56
<div class="repo-button-row-left">

web_src/js/components/ViewFileTreeStore.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,16 @@ export function createViewFileTreeStore(props: {repoLink: string, treePath: stri
2525
},
2626

2727
async loadViewContent(url: string) {
28-
url = url.includes('?') ? url.replace('?', '?only_content=true') : `${url}?only_content=true`;
29-
const response = await GET(url);
30-
document.querySelector('.repo-view-content').innerHTML = await response.text();
28+
const u = new URL(url, window.origin);
29+
u.searchParams.set('only_content', 'true');
30+
const response = await GET(u.href);
31+
const elViewContent = document.querySelector('.repo-view-content');
32+
elViewContent.innerHTML = await response.text();
33+
const elViewContentData = elViewContent.querySelector('.repo-view-content-data');
34+
if (!elViewContentData) return; // if error occurs, there is no such element
35+
const t1 = elViewContentData.getAttribute('data-document-title');
36+
const t2 = elViewContentData.getAttribute('data-document-title-common');
37+
document.title = `${t1} - ${t2}`; // follow the format in head.tmpl: <head><title>...</title></head>
3138
},
3239

3340
async navigateTreeView(treePath: string) {

0 commit comments

Comments
 (0)