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:
wxiaoguang
2026-04-04 01:56:31 +08:00
committed by GitHub
parent d80640fa5d
commit f9f9876f2c
35 changed files with 108 additions and 80 deletions

View File

@@ -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 {

View File

@@ -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"
@@ -34,6 +36,11 @@ type MailRender struct {
mockedBodyTemplates map[string]*template.Template
}
// 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")
}
// mailSubjectTextFuncMap returns functions for injecting to text templates, it's only used for mail subject
func mailSubjectTextFuncMap() texttmpl.FuncMap {
return texttmpl.FuncMap{
@@ -41,6 +48,7 @@ func mailSubjectTextFuncMap() texttmpl.FuncMap {
"Eval": evalTokens,
"EllipsisString": util.EllipsisDisplayString,
"AppName": func() string {
return setting.AppName
},
@@ -50,6 +58,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 +153,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 +181,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

View File

@@ -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
}

View File

@@ -3224,10 +3224,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",

View File

@@ -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()

View File

@@ -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,14 @@ func (c TemplateContext) CurrentWebBanner() *setting.WebBannerType {
}
return nil
}
// AppFullLink returns a full URL link with AppSubURL for the given app link (no AppSubURL)
// 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)
func (c TemplateContext) AppFullLink(link ...string) template.URL {
s := httplib.GuessCurrentAppURL(c.parentContext())
s = strings.TrimSuffix(s, "/")
if len(link) == 0 {
return template.URL(s)
}
return template.URL(s + strings.TrimPrefix(link[0], "/"))
}

View File

@@ -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>

View File

@@ -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.AppFullLink $.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.AppFullLink}}">
<meta property="og:description" content="{{MetaDescription}}">
{{end}}
<meta property="og:site_name" content="{{AppName}}">

View File

@@ -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.AppFullLink "/"}}',
appSubUrl: '{{AppSubUrl}}',
assetUrlPrefix: '{{AssetUrlPrefix}}',
runModeIsProd: {{.RunModeIsProd}},

View File

@@ -84,12 +84,6 @@
</div>
</div>
<div>
<h1>&lt;origin-url&gt;</h1>
<div><origin-url data-url="test/url"></origin-url></div>
<div><origin-url data-url="/test/url"></origin-url></div>
</div>
<div>
<h1>&lt;overflow-menu&gt;</h1>
<overflow-menu class="ui secondary pointing tabular borderless menu">

View File

@@ -4,12 +4,12 @@
<div class="ui form">
<div class="field">
<label>{{svg "octicon-code"}} {{ctx.Locale.Tr "packages.alpine.registry"}}</label>
<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>
<div class="markup"><pre class="code-block"><code>{{ctx.AppFullLink}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/alpine/$branch/$repository</code></pre></div>
<p>{{ctx.Locale.Tr "packages.alpine.registry.info"}}</p>
</div>
<div class="field">
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.alpine.registry.key"}}</label>
<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>
<div class="markup"><pre class="code-block"><code>curl -JO {{ctx.AppFullLink}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/alpine/key</code></pre></div>
</div>
<div class="field">
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.alpine.install"}}</label>

View File

@@ -7,7 +7,7 @@
<div class="markup"><pre class="code-block"><code>{{range $i, $repo := .Repositories}}{{if $i}}
{{end}}[{{$repo}}]
SigLevel = Optional TrustAll
Server = <origin-url data-url="{{AppSubUrl}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/arch/$repo/$arch"></origin-url>
Server = {{ctx.AppFullLink}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/arch/$repo/$arch
{{end}}</code></pre></div>
</div>
<div class="field">

View File

@@ -8,8 +8,8 @@
default = "gitea"
[registries.gitea]
index = "sparse+<origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/cargo/"></origin-url>" # Sparse index
# index = "<origin-url data-url="{{AppSubUrl}}/{{.PackageDescriptor.Owner.Name}}/_cargo-index.git"></origin-url>" # Git
index = "sparse+{{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/cargo/" # Sparse index
# index = "{{ctx.AppFullLink}}/{{.PackageDescriptor.Owner.Name}}/_cargo-index.git" # Git
[net]
git-fetch-with-cli = true</code></pre></div>

View File

@@ -4,7 +4,7 @@
<div class="ui form">
<div class="field">
<label>{{svg "octicon-code"}} {{ctx.Locale.Tr "packages.chef.registry"}}</label>
<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>
<div class="markup"><pre class="code-block"><code>knife[:supermarket_site] = '{{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/chef'</code></pre></div>
</div>
<div class="field">
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.chef.install"}}</label>

View File

@@ -7,7 +7,7 @@
<div class="markup"><pre class="code-block"><code>{
"repositories": [{
"type": "composer",
"url": "<origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/composer"></origin-url>"
"url": "{{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/composer"
}
]
}</code></pre></div>

View File

@@ -4,7 +4,7 @@
<div class="ui form">
<div class="field">
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.conan.registry"}}</label>
<div class="markup"><pre class="code-block"><code>conan remote add gitea <origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/conan"></origin-url></code></pre></div>
<div class="markup"><pre class="code-block"><code>conan remote add gitea {{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/conan</code></pre></div>
</div>
<div class="field">
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.conan.install"}}</label>

View File

@@ -4,11 +4,11 @@
<div class="ui form">
<div class="field">
<label>{{svg "octicon-code"}} {{ctx.Locale.Tr "packages.conda.registry"}}</label>
<div class="markup"><pre class="code-block"><code>channel_alias: <origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/conda"></origin-url>
<div class="markup"><pre class="code-block"><code>channel_alias: {{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/conda
channels:
&#32;&#32;- <origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/conda"></origin-url>
&#32;&#32;- {{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/conda
default_channels:
&#32;&#32;- <origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/conda"></origin-url></code></pre></div>
&#32;&#32;- {{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/conda</code></pre></div>
</div>
<div class="field">
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.conda.install"}}</label>

View File

@@ -4,7 +4,7 @@
<div class="ui form">
<div class="field">
<label>{{svg "octicon-code"}} {{ctx.Locale.Tr "packages.cran.registry"}}</label>
<div class="markup"><pre class="code-block"><code>options("repos" = c(getOption("repos"), c(gitea="<origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/cran"></origin-url>")))</code></pre></div>
<div class="markup"><pre class="code-block"><code>options("repos" = c(getOption("repos"), c(gitea="{{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/cran")))</code></pre></div>
</div>
<div class="field">
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.cran.install"}}</label>

View File

@@ -4,8 +4,8 @@
<div class="ui form">
<div class="field">
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.debian.registry"}}</label>
<div class="markup"><pre class="code-block"><code>sudo curl <origin-url data-url="{{AppSubUrl}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/debian/repository.key"></origin-url> -o /etc/apt/keyrings/gitea-{{$.PackageDescriptor.Owner.Name}}.asc
echo "deb [signed-by=/etc/apt/keyrings/gitea-{{$.PackageDescriptor.Owner.Name}}.asc] <origin-url data-url="{{AppSubUrl}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/debian"></origin-url> $distribution $component" | sudo tee -a /etc/apt/sources.list.d/gitea.list
<div class="markup"><pre class="code-block"><code>sudo curl {{ctx.AppFullLink}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/debian/repository.key -o /etc/apt/keyrings/gitea-{{$.PackageDescriptor.Owner.Name}}.asc
echo "deb [signed-by=/etc/apt/keyrings/gitea-{{$.PackageDescriptor.Owner.Name}}.asc] {{ctx.AppFullLink}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/debian $distribution $component" | sudo tee -a /etc/apt/sources.list.d/gitea.list
sudo apt update</code></pre></div>
<p>{{ctx.Locale.Tr "packages.debian.registry.info"}}</p>
</div>

View File

@@ -6,7 +6,7 @@
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.generic.download"}}</label>
<div class="markup"><pre class="code-block"><code>
{{- range .PackageDescriptor.Files -}}
curl -OJ <origin-url data-url="{{AppSubUrl}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/generic/{{$.PackageDescriptor.Package.Name}}/{{$.PackageDescriptor.Version.Version}}/{{.File.Name}}"></origin-url>
curl -OJ {{ctx.AppFullLink}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/generic/{{$.PackageDescriptor.Package.Name}}/{{$.PackageDescriptor.Version.Version}}/{{.File.Name}}
{{end -}}
</code></pre></div>
</div>

View File

@@ -4,7 +4,7 @@
<div class="ui form">
<div class="field">
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.go.install"}}</label>
<div class="markup"><pre class="code-block"><code>GOPROXY=<origin-url data-url="{{AppSubUrl}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/go"></origin-url> go install {{$.PackageDescriptor.Package.Name}}@{{$.PackageDescriptor.Version.Version}}</code></pre></div>
<div class="markup"><pre class="code-block"><code>GOPROXY={{ctx.AppFullLink}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/go go install {{$.PackageDescriptor.Package.Name}}@{{$.PackageDescriptor.Version.Version}}</code></pre></div>
</div>
<div class="field">
<label>{{ctx.Locale.Tr "packages.registry.documentation" "Go" "https://docs.gitea.com/usage/packages/go"}}</label>

View File

@@ -4,7 +4,7 @@
<div class="ui form">
<div class="field">
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.helm.registry"}}</label>
<div class="markup"><pre class="code-block"><code>helm repo add {{AppDomain}} <origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/helm"></origin-url>
<div class="markup"><pre class="code-block"><code>helm repo add {{AppDomain}} {{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/helm
helm repo update</code></pre></div>
</div>
<div class="field">

View File

@@ -11,19 +11,19 @@
<div class="markup"><pre class="code-block"><code>&lt;repositories&gt;
&lt;repository&gt;
&lt;id&gt;gitea&lt;/id&gt;
&lt;url&gt;<origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/maven"></origin-url>&lt;/url&gt;
&lt;url&gt;{{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/maven&lt;/url&gt;
&lt;/repository&gt;
&lt;/repositories&gt;
&lt;distributionManagement&gt;
&lt;repository&gt;
&lt;id&gt;gitea&lt;/id&gt;
&lt;url&gt;<origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/maven"></origin-url>&lt;/url&gt;
&lt;url&gt;{{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/maven&lt;/url&gt;
&lt;/repository&gt;
&lt;snapshotRepository&gt;
&lt;id&gt;gitea&lt;/id&gt;
&lt;url&gt;<origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/maven"></origin-url>&lt;/url&gt;
&lt;url&gt;{{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/maven&lt;/url&gt;
&lt;/snapshotRepository&gt;
&lt;/distributionManagement&gt;</code></pre></div>
</div>
@@ -41,7 +41,7 @@
</div>
<div class="field">
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.maven.download"}}</label>
<div class="markup"><pre class="code-block"><code>mvn dependency:get -DremoteRepositories=<origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/maven"></origin-url> -Dartifact={{.PackageDescriptor.Metadata.GroupID}}:{{.PackageDescriptor.Metadata.ArtifactID}}:{{.PackageDescriptor.Version.Version}}</code></pre></div>
<div class="markup"><pre class="code-block"><code>mvn dependency:get -DremoteRepositories={{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/maven -Dartifact={{.PackageDescriptor.Metadata.GroupID}}:{{.PackageDescriptor.Metadata.ArtifactID}}:{{.PackageDescriptor.Version.Version}}</code></pre></div>
</div>
<div class="field">
<label>{{ctx.Locale.Tr "packages.registry.documentation" "Maven" "https://docs.gitea.com/usage/packages/maven/"}}</label>

View File

@@ -4,7 +4,7 @@
<div class="ui form">
<div class="field">
<label>{{svg "octicon-code"}} {{ctx.Locale.Tr "packages.npm.registry"}}</label>
<div class="markup"><pre class="code-block"><code>{{if .PackageDescriptor.Metadata.Scope}}{{.PackageDescriptor.Metadata.Scope}}:{{end}}registry=<origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/npm/"></origin-url></code></pre></div>
<div class="markup"><pre class="code-block"><code>{{if .PackageDescriptor.Metadata.Scope}}{{.PackageDescriptor.Metadata.Scope}}:{{end}}registry={{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/npm/</code></pre></div>
</div>
<div class="field">
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.npm.install"}}</label>

View File

@@ -4,7 +4,7 @@
<div class="ui form">
<div class="field">
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.nuget.registry"}}</label>
<div class="markup"><pre class="code-block"><code>dotnet nuget add source --name {{.PackageDescriptor.Owner.Name}} --username your_username --password your_token <origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/nuget/index.json"></origin-url></code></pre></div>
<div class="markup"><pre class="code-block"><code>dotnet nuget add source --name {{.PackageDescriptor.Owner.Name}} --username your_username --password your_token {{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/nuget/index.json</code></pre></div>
</div>
<div class="field">
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.nuget.install"}}</label>

View File

@@ -4,7 +4,7 @@
<div class="ui form">
<div class="field">
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.pub.install"}}</label>
<div class="markup"><pre class="code-block"><code>dart pub add {{.PackageDescriptor.Package.Name}}:{{.PackageDescriptor.Version.Version}} --hosted-url=<origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/pub/"></origin-url></code></pre></div>
<div class="markup"><pre class="code-block"><code>dart pub add {{.PackageDescriptor.Package.Name}}:{{.PackageDescriptor.Version.Version}} --hosted-url={{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/pub/</code></pre></div>
</div>
<div class="field">
<label>{{ctx.Locale.Tr "packages.registry.documentation" "Pub" "https://docs.gitea.com/usage/packages/pub/"}}</label>

View File

@@ -4,7 +4,7 @@
<div class="ui form">
<div class="field">
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.pypi.install"}}</label>
<div class="markup"><pre class="code-block"><code>pip install --index-url <origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/pypi/simple/"></origin-url> --extra-index-url https://pypi.org/simple {{.PackageDescriptor.Package.Name}}</code></pre></div>
<div class="markup"><pre class="code-block"><code>pip install --index-url {{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/pypi/simple/ --extra-index-url https://pypi.org/simple {{.PackageDescriptor.Package.Name}}</code></pre></div>
</div>
<div class="field">
<label>{{ctx.Locale.Tr "packages.registry.documentation" "PyPI" "https://docs.gitea.com/usage/packages/pypi/"}}</label>

View File

@@ -11,19 +11,19 @@
# {{ctx.Locale.Tr "packages.rpm.distros.redhat"}}
{{- range $group := .Groups}}
{{- if $group}}{{$group = print "/" $group}}{{end}}
dnf config-manager --add-repo <origin-url data-url="{{AppSubUrl}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/rpm{{$group}}.repo"></origin-url>
dnf config-manager --add-repo {{ctx.AppFullLink}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/rpm{{$group}}.repo
{{- end}}
# Fedora 41+ (DNF5)
{{- range $group := .Groups}}
{{- if $group}}{{$group = print "/" $group}}{{end}}
dnf config-manager addrepo --from-repofile=<origin-url data-url="{{AppSubUrl}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/rpm{{$group}}.repo"></origin-url>
dnf config-manager addrepo --from-repofile={{ctx.AppFullLink}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/rpm{{$group}}.repo
{{- end}}
# {{ctx.Locale.Tr "packages.rpm.distros.suse"}}
{{- range $group := .Groups}}
{{- if $group}}{{$group = print "/" $group}}{{end}}
zypper addrepo <origin-url data-url="{{AppSubUrl}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/rpm{{$group}}.repo"></origin-url>
zypper addrepo {{ctx.AppFullLink}}/api/packages/{{$.PackageDescriptor.Owner.Name}}/rpm{{$group}}.repo
{{- end}}</code></pre></div>
</div>
<div class="field">

View File

@@ -4,11 +4,11 @@
<div class="ui form">
<div class="field">
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.rubygems.install"}}:</label>
<div class="markup"><pre class="code-block"><code>gem install {{.PackageDescriptor.Package.Name}} --version &quot;{{.PackageDescriptor.Version.Version}}&quot; --source &quot;<origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/rubygems"></origin-url>&quot;</code></pre></div>
<div class="markup"><pre class="code-block"><code>gem install {{.PackageDescriptor.Package.Name}} --version &quot;{{.PackageDescriptor.Version.Version}}&quot; --source &quot;{{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/rubygems&quot;</code></pre></div>
</div>
<div class="field">
<label>{{svg "octicon-code"}} {{ctx.Locale.Tr "packages.rubygems.install2"}}:</label>
<div class="markup"><pre class="code-block"><code>source "<origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/rubygems"></origin-url>" do
<div class="markup"><pre class="code-block"><code>source "{{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/rubygems" do
gem "{{.PackageDescriptor.Package.Name}}", "{{.PackageDescriptor.Version.Version}}"
end</code></pre></div>
</div>

View File

@@ -4,7 +4,7 @@
<div class="ui form">
<div class="field">
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.swift.registry"}}</label>
<div class="markup"><pre class="code-block"><code>swift package-registry set <origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/swift"></origin-url></code></pre></div>
<div class="markup"><pre class="code-block"><code>swift package-registry set {{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/swift</code></pre></div>
</div>
<div class="field">
<label>{{svg "octicon-code"}} {{ctx.Locale.Tr "packages.swift.install"}}</label>

View File

@@ -4,7 +4,7 @@
<div class="ui form">
<div class="field">
<label>{{svg "octicon-terminal"}} {{ctx.Locale.Tr "packages.vagrant.install"}}</label>
<div class="markup"><pre class="code-block"><code>vagrant box add --box-version {{.PackageDescriptor.Version.Version}} "<origin-url data-url="{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/vagrant/{{.PackageDescriptor.Package.Name}}"></origin-url>"</code></pre></div>
<div class="markup"><pre class="code-block"><code>vagrant box add --box-version {{.PackageDescriptor.Version.Version}} "{{ctx.AppFullLink}}/api/packages/{{.PackageDescriptor.Owner.Name}}/vagrant/{{.PackageDescriptor.Package.Name}}"</code></pre></div>
</div>
<div class="field">
<label>{{ctx.Locale.Tr "packages.registry.documentation" "Vagrant" "https://docs.gitea.com/usage/packages/vagrant/"}}</label>

View File

@@ -10,7 +10,7 @@
<div class="ui secondary segment tw-font-mono">
{{$gitRemoteName := ctx.RootData.SystemConfig.Repository.GitGuideRemoteName.Value ctx}}
{{if eq .PullRequest.Flow 0}}
<div>git fetch -u {{if ne .PullRequest.HeadRepo.ID .PullRequest.BaseRepo.ID}}<origin-url data-url="{{.PullRequest.HeadRepo.Link}}"></origin-url>{{else}}{{$gitRemoteName}}{{end}} {{.PullRequest.HeadBranch}}:{{$localBranch}}</div>
<div>git fetch -u {{if ne .PullRequest.HeadRepo.ID .PullRequest.BaseRepo.ID}}{{ctx.AppFullLink .PullRequest.HeadRepo.Link}}{{else}}{{$gitRemoteName}}{{end}} {{.PullRequest.HeadBranch}}:{{$localBranch}}</div>
{{else}}
<div>git fetch -u {{$gitRemoteName}} {{.PullRequest.GetGitHeadRefName}}:{{$localBranch}}</div>
{{end}}

View File

@@ -32,7 +32,6 @@ for (const path of globSync('web_src/css/themes/*.css', {cwd: import.meta.dirnam
const webComponents = new Set([
// our own, in web_src/js/webcomponents
'overflow-menu',
'origin-url',
'relative-time',
// from dependencies
'markdown-toolbar',

View File

@@ -1,6 +1,5 @@
import './polyfills.ts';
import './relative-time.ts';
import './origin-url.ts';
import './overflow-menu.ts';
import {isDarkTheme} from '../utils.ts';

View File

@@ -1,7 +0,0 @@
import {toOriginUrl} from '../utils/url.ts';
window.customElements.define('origin-url', class extends HTMLElement {
connectedCallback() {
this.textContent = toOriginUrl(this.getAttribute('data-url')!);
}
});