mirror of
https://github.com/go-gitea/gitea.git
synced 2025-11-02 13:23:30 +01:00
Update tab title when navigating file tree (#35757)
Fix #35749. --------- Signed-off-by: silverwind <me@silverwind.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
parent
fe25997157
commit
39c08ce4c1
@ -22,6 +22,8 @@ func GetContextData(c context.Context) reqctx.ContextData {
|
|||||||
|
|
||||||
func CommonTemplateContextData() reqctx.ContextData {
|
func CommonTemplateContextData() reqctx.ContextData {
|
||||||
return reqctx.ContextData{
|
return reqctx.ContextData{
|
||||||
|
"PageTitleCommon": setting.AppName,
|
||||||
|
|
||||||
"IsLandingPageOrganizations": setting.LandingPageURL == setting.LandingPageOrganizations,
|
"IsLandingPageOrganizations": setting.LandingPageURL == setting.LandingPageOrganizations,
|
||||||
|
|
||||||
"ShowRegistrationButton": setting.Service.ShowRegistrationButton,
|
"ShowRegistrationButton": setting.Service.ShowRegistrationButton,
|
||||||
|
|||||||
@ -172,7 +172,7 @@ func prepareFileView(ctx *context.Context, entry *git.TreeEntry) {
|
|||||||
|
|
||||||
blob := entry.Blob()
|
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["FileIsSymlink"] = entry.IsLink()
|
||||||
ctx.Data["FileTreePath"] = ctx.Repo.TreePath
|
ctx.Data["FileTreePath"] = ctx.Repo.TreePath
|
||||||
ctx.Data["RawFileLink"] = ctx.Repo.RepoLink + "/raw/" + ctx.Repo.RefTypeNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
|
ctx.Data["RawFileLink"] = ctx.Repo.RepoLink + "/raw/" + ctx.Repo.RefTypeNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -146,7 +145,7 @@ func prepareToRenderDirectory(ctx *context.Context) {
|
|||||||
|
|
||||||
if ctx.Repo.TreePath != "" {
|
if ctx.Repo.TreePath != "" {
|
||||||
ctx.Data["HideRepoInfo"] = true
|
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)
|
subfolder, readmeFile, err := findReadmeFileInEntries(ctx, ctx.Repo.TreePath, entries, true)
|
||||||
|
|||||||
@ -537,6 +537,7 @@ func RepoAssignment(ctx *Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["Title"] = repo.Owner.Name + "/" + repo.Name
|
ctx.Data["Title"] = repo.Owner.Name + "/" + repo.Name
|
||||||
|
ctx.Data["PageTitleCommon"] = repo.Name + " - " + setting.AppName
|
||||||
ctx.Data["Repository"] = repo
|
ctx.Data["Repository"] = repo
|
||||||
ctx.Data["Owner"] = ctx.Repo.Repository.Owner
|
ctx.Data["Owner"] = ctx.Repo.Repository.Owner
|
||||||
ctx.Data["CanWriteCode"] = ctx.Repo.CanWrite(unit_model.TypeCode)
|
ctx.Data["CanWriteCode"] = ctx.Repo.CanWrite(unit_model.TypeCode)
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
<html lang="{{ctx.Locale.Lang}}" data-theme="{{ctx.CurrentWebTheme.InternalName}}">
|
<html lang="{{ctx.Locale.Lang}}" data-theme="{{ctx.CurrentWebTheme.InternalName}}">
|
||||||
<head>
|
<head>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>{{if .Title}}{{.Title}} - {{end}}{{if .Repository.Name}}{{.Repository.Name}} - {{end}}{{AppName}}</title>
|
<title>{{if .Title}}{{.Title}} - {{end}}{{.PageTitleCommon}}</title>
|
||||||
{{if .ManifestData}}<link rel="manifest" href="data:{{.ManifestData}}">{{end}}
|
{{if .ManifestData}}<link rel="manifest" href="data:{{.ManifestData}}">{{end}}
|
||||||
<meta name="author" content="{{if .Repository}}{{.Owner.Name}}{{else}}{{MetaAuthor}}{{end}}">
|
<meta name="author" content="{{if .Repository}}{{.Owner.Name}}{{else}}{{MetaAuthor}}{{end}}">
|
||||||
<meta name="description" content="{{if .Repository}}{{.Repository.Name}}{{if .Repository.Description}} - {{.Repository.Description}}{{end}}{{else}}{{MetaDescription}}{{end}}">
|
<meta name="description" content="{{if .Repository}}{{.Repository.Name}}{{if .Repository.Description}} - {{.Repository.Description}}{{end}}{{else}}{{MetaDescription}}{{end}}">
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
{{$isTreePathRoot := not .TreeNames}}
|
{{$isTreePathRoot := not .TreeNames}}
|
||||||
|
|
||||||
|
<div class="repo-view-content-data tw-hidden" data-document-title="{{ctx.RootData.Title}}" data-document-title-common="{{ctx.RootData.PageTitleCommon}}"></div>
|
||||||
{{template "repo/sub_menu" .}}
|
{{template "repo/sub_menu" .}}
|
||||||
<div class="repo-button-row">
|
<div class="repo-button-row">
|
||||||
<div class="repo-button-row-left">
|
<div class="repo-button-row-left">
|
||||||
|
|||||||
@ -25,9 +25,16 @@ export function createViewFileTreeStore(props: {repoLink: string, treePath: stri
|
|||||||
},
|
},
|
||||||
|
|
||||||
async loadViewContent(url: string) {
|
async loadViewContent(url: string) {
|
||||||
url = url.includes('?') ? url.replace('?', '?only_content=true') : `${url}?only_content=true`;
|
const u = new URL(url, window.origin);
|
||||||
const response = await GET(url);
|
u.searchParams.set('only_content', 'true');
|
||||||
document.querySelector('.repo-view-content').innerHTML = await response.text();
|
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: <head><title>...</title></head>
|
||||||
},
|
},
|
||||||
|
|
||||||
async navigateTreeView(treePath: string) {
|
async navigateTreeView(treePath: string) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user