mirror of
https://github.com/go-gitea/gitea.git
synced 2026-04-04 07:55:31 +02:00
fix
This commit is contained in:
parent
7b17234945
commit
0b9cba662d
@ -25,8 +25,8 @@ import (
|
||||
"code.gitea.io/gitea/services/gitdiff"
|
||||
)
|
||||
|
||||
// NewFuncMap returns functions for injecting to templates
|
||||
func NewFuncMap() template.FuncMap {
|
||||
// newFuncMapWebPage returns functions for injecting to templates
|
||||
func newFuncMapWebPage() template.FuncMap {
|
||||
return map[string]any{
|
||||
"DumpVar": dumpVar,
|
||||
"NIL": func() any { return nil },
|
||||
@ -40,7 +40,6 @@ func NewFuncMap() template.FuncMap {
|
||||
"QueryEscape": queryEscape,
|
||||
"QueryBuild": QueryBuild,
|
||||
"SanitizeHTML": SanitizeHTML,
|
||||
"DotEscape": dotEscape,
|
||||
|
||||
"PathEscape": url.PathEscape,
|
||||
"PathEscapeSegments": util.PathEscapeSegments,
|
||||
@ -61,6 +60,7 @@ func NewFuncMap() template.FuncMap {
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// time / number / format
|
||||
"ShortSha": base.ShortSha,
|
||||
"FileSize": base.FileSize,
|
||||
"CountFmt": countFmt,
|
||||
"Sec2Hour": util.SecToHours,
|
||||
@ -73,6 +73,7 @@ func NewFuncMap() template.FuncMap {
|
||||
|
||||
"AssetURI": public.AssetURI,
|
||||
"ScriptImport": scriptImport,
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// setting
|
||||
"AppName": func() string {
|
||||
@ -84,17 +85,10 @@ func NewFuncMap() template.FuncMap {
|
||||
"AssetUrlPrefix": func() string {
|
||||
return setting.StaticURLPrefix + "/assets"
|
||||
},
|
||||
"AppUrl": func() string {
|
||||
// The usage of AppUrl should be avoided as much as possible,
|
||||
// because the AppURL(ROOT_URL) may not match user's visiting site and the ROOT_URL in app.ini may be incorrect.
|
||||
// And it's difficult for Gitea to guess absolute URL correctly with zero configuration,
|
||||
// because Gitea doesn't know whether the scheme is HTTP or HTTPS unless the reverse proxy could tell Gitea.
|
||||
return setting.AppURL
|
||||
},
|
||||
"AppVer": func() string {
|
||||
return setting.AppVer
|
||||
},
|
||||
"AppDomain": func() string { // documented in mail-templates.md
|
||||
"AppDomain": func() string { // TODO: helm char registry still uses it, need to use current host
|
||||
return setting.Domain
|
||||
},
|
||||
"ShowFooterTemplateLoadTime": func() bool {
|
||||
@ -143,7 +137,6 @@ func NewFuncMap() template.FuncMap {
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// misc (TODO: move them to MiscUtils to avoid bloating the main func map)
|
||||
"ShortSha": base.ShortSha,
|
||||
"ActionContent2Commits": ActionContent2Commits,
|
||||
"IsMultilineCommitMessage": isMultilineCommitMessage,
|
||||
"CommentMustAsDiff": gitdiff.CommentMustAsDiff,
|
||||
|
||||
@ -6,12 +6,14 @@ package templates
|
||||
import (
|
||||
"html/template"
|
||||
"io"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
texttmpl "text/template"
|
||||
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
@ -41,6 +43,7 @@ func mailSubjectTextFuncMap() texttmpl.FuncMap {
|
||||
"Eval": evalTokens,
|
||||
|
||||
"EllipsisString": util.EllipsisDisplayString,
|
||||
|
||||
"AppName": func() string {
|
||||
return setting.AppName
|
||||
},
|
||||
@ -50,6 +53,48 @@ func mailSubjectTextFuncMap() texttmpl.FuncMap {
|
||||
}
|
||||
}
|
||||
|
||||
func mailBodyFuncMap() template.FuncMap {
|
||||
// Some of them are documented in mail-templates.md
|
||||
return template.FuncMap{
|
||||
"DumpVar": dumpVar,
|
||||
"NIL": func() any { return nil },
|
||||
|
||||
// html/template related functions
|
||||
"dict": dict,
|
||||
"Iif": iif,
|
||||
"Eval": evalTokens,
|
||||
"HTMLFormat": htmlFormat,
|
||||
"QueryEscape": queryEscape,
|
||||
"QueryBuild": QueryBuild,
|
||||
"SanitizeHTML": SanitizeHTML,
|
||||
|
||||
"PathEscape": url.PathEscape,
|
||||
"PathEscapeSegments": util.PathEscapeSegments,
|
||||
|
||||
"DotEscape": dotEscape,
|
||||
|
||||
// utils
|
||||
"StringUtils": NewStringUtils,
|
||||
"SliceUtils": NewSliceUtils,
|
||||
"JsonUtils": NewJsonUtils,
|
||||
|
||||
// time / number / format
|
||||
"ShortSha": base.ShortSha,
|
||||
"FileSize": base.FileSize,
|
||||
|
||||
// setting
|
||||
"AppName": func() string {
|
||||
return setting.AppName
|
||||
},
|
||||
"AppUrl": func() string {
|
||||
return setting.AppURL
|
||||
},
|
||||
"AppDomain": func() string {
|
||||
return setting.Domain
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
var mailSubjectSplit = regexp.MustCompile(`(?m)^-{3,}\s*$`)
|
||||
|
||||
func newMailRenderer() (*MailRender, error) {
|
||||
@ -103,7 +148,7 @@ func newMailRenderer() (*MailRender, error) {
|
||||
return renderer.tmplRenderer.Templates().HasTemplate(name)
|
||||
}
|
||||
|
||||
staticFuncMap := NewFuncMap()
|
||||
staticFuncMap := mailBodyFuncMap()
|
||||
renderer.BodyTemplates.ExecuteTemplate = func(w io.Writer, name string, data any) error {
|
||||
if t, ok := renderer.mockedBodyTemplates[name]; ok {
|
||||
return t.Execute(w, data)
|
||||
@ -131,7 +176,7 @@ func (r *MailRender) MockTemplate(name, subject, body string) func() {
|
||||
texttmpl.Must(r.SubjectTemplates.New(name).Parse(subject))
|
||||
|
||||
oldBody, hasOldBody := r.mockedBodyTemplates[name]
|
||||
mockFuncMap := NewFuncMap()
|
||||
mockFuncMap := mailBodyFuncMap()
|
||||
r.mockedBodyTemplates[name] = template.Must(template.New(name).Funcs(mockFuncMap).Parse(body))
|
||||
return func() {
|
||||
r.SubjectTemplates = oldSubject
|
||||
|
||||
@ -24,13 +24,13 @@ type pageRenderer struct {
|
||||
}
|
||||
|
||||
func (r *pageRenderer) funcMap(ctx context.Context) template.FuncMap {
|
||||
pageFuncMap := NewFuncMap()
|
||||
pageFuncMap := newFuncMapWebPage()
|
||||
pageFuncMap["ctx"] = func() any { return ctx }
|
||||
return pageFuncMap
|
||||
}
|
||||
|
||||
func (r *pageRenderer) funcMapDummy() template.FuncMap {
|
||||
dummyFuncMap := NewFuncMap()
|
||||
dummyFuncMap := newFuncMapWebPage()
|
||||
dummyFuncMap["ctx"] = func() any { return nil } // for template compilation only, no context available
|
||||
return dummyFuncMap
|
||||
}
|
||||
|
||||
@ -3223,10 +3223,8 @@
|
||||
"admin.config.server_config": "Server Configuration",
|
||||
"admin.config.app_name": "Site Title",
|
||||
"admin.config.app_ver": "Gitea Version",
|
||||
"admin.config.app_url": "Gitea Base URL",
|
||||
"admin.config.custom_conf": "Configuration File Path",
|
||||
"admin.config.custom_file_root_path": "Custom File Root Path",
|
||||
"admin.config.domain": "Server Domain",
|
||||
"admin.config.disable_router_log": "Disable Router Log",
|
||||
"admin.config.run_user": "Run As Username",
|
||||
"admin.config.run_mode": "Run Mode",
|
||||
|
||||
@ -123,9 +123,7 @@ func Config(ctx *context.Context) {
|
||||
ctx.Data["PageIsAdminConfigSummary"] = true
|
||||
|
||||
ctx.Data["CustomConf"] = setting.CustomConf
|
||||
ctx.Data["AppUrl"] = setting.AppURL
|
||||
ctx.Data["AppBuiltWith"] = setting.AppBuiltWith
|
||||
ctx.Data["Domain"] = setting.Domain
|
||||
ctx.Data["RunUser"] = setting.RunUser
|
||||
ctx.Data["RunMode"] = util.ToTitleCase(setting.RunMode)
|
||||
ctx.Data["GitVersion"] = git.DefaultFeatures().VersionInfo()
|
||||
|
||||
@ -5,10 +5,13 @@ package context
|
||||
|
||||
import (
|
||||
"context"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/httplib"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/web/middleware"
|
||||
"code.gitea.io/gitea/services/webtheme"
|
||||
@ -69,3 +72,9 @@ func (c TemplateContext) CurrentWebBanner() *setting.WebBannerType {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c TemplateContext) MakeAppURL(link string) template.URL {
|
||||
s := httplib.GuessCurrentAppURL(c.parentContext())
|
||||
s = strings.TrimSuffix(s, "/")
|
||||
return template.URL(s + strings.TrimPrefix(link, "/"))
|
||||
}
|
||||
|
||||
@ -11,10 +11,6 @@
|
||||
<dd>{{AppVer}}{{.AppBuiltWith}}</dd>
|
||||
<dt>{{ctx.Locale.Tr "admin.config.custom_conf"}}</dt>
|
||||
<dd>{{.CustomConf}}</dd>
|
||||
<dt>{{ctx.Locale.Tr "admin.config.app_url"}}</dt>
|
||||
<dd>{{.AppUrl}}</dd>
|
||||
<dt>{{ctx.Locale.Tr "admin.config.domain"}}</dt>
|
||||
<dd>{{.Domain}}</dd>
|
||||
<dt>{{ctx.Locale.Tr "admin.config.disable_router_log"}}</dt>
|
||||
<dd>{{svg (Iif .DisableRouterLog "octicon-check" "octicon-x")}}</dd>
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
{{end}}
|
||||
{{else if or .PageIsDiff .IsViewFile}}
|
||||
<meta property="og:title" content="{{.Title}}">
|
||||
<meta property="og:url" content="{{AppUrl}}{{.Link}}">
|
||||
<meta property="og:url" content="{{ctx.MakeAppURL $.Link}}">
|
||||
{{if and .PageIsDiff .Commit}}
|
||||
{{- $commitMessageParts := StringUtils.Cut .Commit.Message "\n" -}}
|
||||
{{- $commitMessageBody := index $commitMessageParts 1 -}}
|
||||
@ -41,7 +41,7 @@
|
||||
<meta property="og:title" content="{{AppName}}">
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:image" content="{{AssetUrlPrefix}}/img/logo.png">
|
||||
<meta property="og:url" content="{{AppUrl}}">
|
||||
<meta property="og:url" content="{{ctx.MakeAppURL ""}}">
|
||||
<meta property="og:description" content="{{MetaDescription}}">
|
||||
{{end}}
|
||||
<meta property="og:site_name" content="{{AppName}}">
|
||||
|
||||
@ -7,7 +7,7 @@ If you introduce mistakes in it, Gitea JavaScript code wouldn't run correctly.
|
||||
window.addEventListener('error', function(e) {window._globalHandlerErrors=window._globalHandlerErrors||[]; window._globalHandlerErrors.push(e);});
|
||||
window.addEventListener('unhandledrejection', function(e) {window._globalHandlerErrors=window._globalHandlerErrors||[]; window._globalHandlerErrors.push(e);});
|
||||
window.config = {
|
||||
appUrl: '{{AppUrl}}',
|
||||
appUrl: '{{ctx.MakeAppURL ""}}',
|
||||
appSubUrl: '{{AppSubUrl}}',
|
||||
assetUrlPrefix: '{{AssetUrlPrefix}}',
|
||||
runModeIsProd: {{.RunModeIsProd}},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user