Skip to content

Commit 96cf9a6

Browse files
committed
remove origin-url
1 parent 0b9cba6 commit 96cf9a6

30 files changed

Lines changed: 49 additions & 59 deletions

modules/templates/helper.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"code.gitea.io/gitea/services/gitdiff"
2626
)
2727

28-
// newFuncMapWebPage returns functions for injecting to templates
2928
func newFuncMapWebPage() template.FuncMap {
3029
return map[string]any{
3130
"DumpVar": dumpVar,
@@ -88,7 +87,7 @@ func newFuncMapWebPage() template.FuncMap {
8887
"AppVer": func() string {
8988
return setting.AppVer
9089
},
91-
"AppDomain": func() string { // TODO: helm char registry still uses it, need to use current host
90+
"AppDomain": func() string { // TODO: helm registry still uses it, need to use current request host in the future
9291
return setting.Domain
9392
},
9493
"ShowFooterTemplateLoadTime": func() bool {
@@ -170,11 +169,6 @@ func queryEscape(s string) template.URL {
170169
return template.URL(url.QueryEscape(s))
171170
}
172171

173-
// dotEscape wraps a dots in names with ZWJ [U+200D] in order to prevent auto-linkers from detecting these as urls
174-
func dotEscape(raw string) string {
175-
return strings.ReplaceAll(raw, ".", "\u200d.\u200d")
176-
}
177-
178172
// iif is an "inline-if", similar util.Iif[T] but templates need the non-generic version,
179173
// and it could be simply used as "{{iif expr trueVal}}" (omit the falseVal).
180174
func iif(condition any, vals ...any) any {

modules/templates/mail.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ type MailRender struct {
3636
mockedBodyTemplates map[string]*template.Template
3737
}
3838

39+
// dotEscape wraps a dots in names with ZWJ [U+200D] in order to prevent auto-linkers from detecting these as urls
40+
func dotEscape(raw string) string {
41+
return strings.ReplaceAll(raw, ".", "\u200d.\u200d")
42+
}
43+
3944
// mailSubjectTextFuncMap returns functions for injecting to text templates, it's only used for mail subject
4045
func mailSubjectTextFuncMap() texttmpl.FuncMap {
4146
return texttmpl.FuncMap{

services/context/context_template.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,13 @@ func (c TemplateContext) CurrentWebBanner() *setting.WebBannerType {
7373
return nil
7474
}
7575

76-
func (c TemplateContext) MakeAppURL(link string) template.URL {
76+
// AppFullLink returns a full URL link with AppSubURL for the given app link (no AppSubURL)
77+
// If no link is given, it returns the current app full URL with sub-path but without trailing slash (that's why it is not named as AppURL)
78+
func (c TemplateContext) AppFullLink(link ...string) template.URL {
7779
s := httplib.GuessCurrentAppURL(c.parentContext())
7880
s = strings.TrimSuffix(s, "/")
79-
return template.URL(s + strings.TrimPrefix(link, "/"))
81+
if len(link) == 0 {
82+
return template.URL(s)
83+
}
84+
return template.URL(s + strings.TrimPrefix(link[0], "/"))
8085
}

templates/base/head_opengraph.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
{{end}}
1717
{{else if or .PageIsDiff .IsViewFile}}
1818
<meta property="og:title" content="{{.Title}}">
19-
<meta property="og:url" content="{{ctx.MakeAppURL $.Link}}">
19+
<meta property="og:url" content="{{ctx.AppFullLink $.Link}}">
2020
{{if and .PageIsDiff .Commit}}
2121
{{- $commitMessageParts := StringUtils.Cut .Commit.Message "\n" -}}
2222
{{- $commitMessageBody := index $commitMessageParts 1 -}}
@@ -41,7 +41,7 @@
4141
<meta property="og:title" content="{{AppName}}">
4242
<meta property="og:type" content="website">
4343
<meta property="og:image" content="{{AssetUrlPrefix}}/img/logo.png">
44-
<meta property="og:url" content="{{ctx.MakeAppURL ""}}">
44+
<meta property="og:url" content="{{ctx.AppFullLink}}">
4545
<meta property="og:description" content="{{MetaDescription}}">
4646
{{end}}
4747
<meta property="og:site_name" content="{{AppName}}">

templates/base/head_script.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ If you introduce mistakes in it, Gitea JavaScript code wouldn't run correctly.
77
window.addEventListener('error', function(e) {window._globalHandlerErrors=window._globalHandlerErrors||[]; window._globalHandlerErrors.push(e);});
88
window.addEventListener('unhandledrejection', function(e) {window._globalHandlerErrors=window._globalHandlerErrors||[]; window._globalHandlerErrors.push(e);});
99
window.config = {
10-
appUrl: '{{ctx.MakeAppURL ""}}',
10+
appUrl: '{{ctx.AppFullLink "/"}}',
1111
appSubUrl: '{{AppSubUrl}}',
1212
assetUrlPrefix: '{{AssetUrlPrefix}}',
1313
runModeIsProd: {{.RunModeIsProd}},

templates/devtest/gitea-ui.tmpl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,6 @@
8484
</div>
8585
</div>
8686

87-
<div>
88-
<h1>&lt;origin-url&gt;</h1>
89-
<div><origin-url data-url="test/url"></origin-url></div>
90-
<div><origin-url data-url="/test/url"></origin-url></div>
91-
</div>
92-
9387
<div>
9488
<h1>&lt;overflow-menu&gt;</h1>
9589
<overflow-menu class="ui secondary pointing tabular borderless menu">

templates/package/content/alpine.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
<div class="ui form">
55
<div class="field">
66
<label>{{svg "octicon-code"}} {{ctx.Locale.Tr "packages.alpine.registry"}}</label>
7-
<div class="markup"><pre class="code-block"><code><origin-url data-url="{{AppSubUrl}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/alpine"></origin-url>/$branch/$repository</code></pre></div>
7+
<div class="markup"><pre class="code-block"><code>{{ctx.AppFullLink}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/alpine/$branch/$repository</code></pre></div>
88
<p>{{ctx.Locale.Tr "packages.alpine.registry.info"}}</p>
99
</div>
1010
<div class="field">
1111
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.alpine.registry.key"}}</label>
12-
<div class="markup"><pre class="code-block"><code>curl -JO <origin-url data-url="{{AppSubUrl}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/alpine/key"></origin-url></code></pre></div>
12+
<div class="markup"><pre class="code-block"><code>curl -JO {{ctx.AppFullLink}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/alpine/key</code></pre></div>
1313
</div>
1414
<div class="field">
1515
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.alpine.install"}}</label>

templates/package/content/arch.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<div class="markup"><pre class="code-block"><code>{{range $i, $repo := .Repositories}}{{if $i}}
88
{{end}}[{{$repo}}]
99
SigLevel = Optional TrustAll
10-
Server = <origin-url data-url="{{AppSubUrl}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/arch/$repo/$arch"></origin-url>
10+
Server = {{ctx.AppFullLink}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/arch/$repo/$arch
1111
{{end}}</code></pre></div>
1212
</div>
1313
<div class="field">

templates/package/content/cargo.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
default = "gitea"
99

1010
[registries.gitea]
11-
index = "sparse+<origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/cargo/"></origin-url>" # Sparse index
12-
# index = "<origin-url data-url="{{AppSubUrl}}/{{.PackageDescriptor.Owner.Name}}/_cargo-index.git"></origin-url>" # Git
11+
index = "sparse+{{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/cargo/" # Sparse index
12+
# index = "{{ctx.AppFullLink}}/{{.PackageDescriptor.Owner.Name}}/_cargo-index.git" # Git
1313

1414
[net]
1515
git-fetch-with-cli = true</code></pre></div>

templates/package/content/chef.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="ui form">
55
<div class="field">
66
<label>{{svg "octicon-code"}} {{ctx.Locale.Tr "packages.chef.registry"}}</label>
7-
<div class="markup"><pre class="code-block"><code>knife[:supermarket_site] = '<origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/chef"></origin-url>'</code></pre></div>
7+
<div class="markup"><pre class="code-block"><code>knife[:supermarket_site] = '{{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/chef'</code></pre></div>
88
</div>
99
<div class="field">
1010
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.chef.install"}}</label>

0 commit comments

Comments
 (0)