Clean up AppURL, remove legacy origin-url webcomponent (#37090)
1. `origin-url` was introduced in the past when there was no good
framework support to detect current host url
* It is not needed anymore
* Removing it makes the code clearer
2. Separate template helper functions for different templates (web
page/mail)
3. The "AppURL" info is removed from admin config page: it doesn't
really help.
* We already have various app url checks at many places
This commit is contained in:
@@ -25,8 +25,7 @@ import (
|
||||
"code.gitea.io/gitea/services/gitdiff"
|
||||
)
|
||||
|
||||
// NewFuncMap returns functions for injecting to templates
|
||||
func NewFuncMap() template.FuncMap {
|
||||
func newFuncMapWebPage() template.FuncMap {
|
||||
return map[string]any{
|
||||
"DumpVar": dumpVar,
|
||||
"NIL": func() any { return nil },
|
||||
@@ -40,7 +39,6 @@ func NewFuncMap() template.FuncMap {
|
||||
"QueryEscape": queryEscape,
|
||||
"QueryBuild": QueryBuild,
|
||||
"SanitizeHTML": SanitizeHTML,
|
||||
"DotEscape": dotEscape,
|
||||
|
||||
"PathEscape": url.PathEscape,
|
||||
"PathEscapeSegments": util.PathEscapeSegments,
|
||||
@@ -61,6 +59,7 @@ func NewFuncMap() template.FuncMap {
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// time / number / format
|
||||
"ShortSha": base.ShortSha,
|
||||
"FileSize": base.FileSize,
|
||||
"CountFmt": countFmt,
|
||||
"Sec2Hour": util.SecToHours,
|
||||
@@ -73,6 +72,7 @@ func NewFuncMap() template.FuncMap {
|
||||
|
||||
"AssetURI": public.AssetURI,
|
||||
"ScriptImport": scriptImport,
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// setting
|
||||
"AppName": func() string {
|
||||
@@ -84,17 +84,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 registry still uses it, need to use current request host in the future
|
||||
return setting.Domain
|
||||
},
|
||||
"ShowFooterTemplateLoadTime": func() bool {
|
||||
@@ -143,7 +136,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,
|
||||
@@ -177,11 +169,6 @@ func queryEscape(s string) template.URL {
|
||||
return template.URL(url.QueryEscape(s))
|
||||
}
|
||||
|
||||
// dotEscape wraps a dots in names with ZWJ [U+200D] in order to prevent auto-linkers from detecting these as urls
|
||||
func dotEscape(raw string) string {
|
||||
return strings.ReplaceAll(raw, ".", "\u200d.\u200d")
|
||||
}
|
||||
|
||||
// iif is an "inline-if", similar util.Iif[T] but templates need the non-generic version,
|
||||
// and it could be simply used as "{{iif expr trueVal}}" (omit the falseVal).
|
||||
func iif(condition any, vals ...any) any {
|
||||
|
||||
Reference in New Issue
Block a user