summaryrefslogtreecommitdiffstats
path: root/templates/base
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-08-08 09:22:47 +0800
committerGitHub <noreply@github.com>2023-08-08 01:22:47 +0000
commit69130532239ee7ade82977f456c12826e1adeb1e (patch)
tree81b8131bedc592af753481b7d222263b2c2655dc /templates/base
parent0c6ae61229bce9d9ad3d359cee927464968a2dd1 (diff)
downloadgitea-69130532239ee7ade82977f456c12826e1adeb1e.tar.gz
gitea-69130532239ee7ade82977f456c12826e1adeb1e.zip
Start using template context function (#26254)
Before: * `{{.locale.Tr ...}}` * `{{$.locale.Tr ...}}` * `{{$.root.locale.Tr ...}}` * `{{template "sub" .}}` * `{{template "sub" (dict "locale" $.locale)}}` * `{{template "sub" (dict "root" $)}}` * ..... With context function: only need to `{{ctx.Locale.Tr ...}}` The "ctx" could be considered as a super-global variable for all templates including sub-templates. To avoid potential risks (any bug in the template context function package), this PR only starts using "ctx" in "head.tmpl" and "footer.tmpl" and it has a "DataRaceCheck". If there is anything wrong, the code can be fixed or reverted easily.
Diffstat (limited to 'templates/base')
-rw-r--r--templates/base/footer.tmpl4
-rw-r--r--templates/base/head.tmpl13
2 files changed, 10 insertions, 7 deletions
diff --git a/templates/base/footer.tmpl b/templates/base/footer.tmpl
index e3cac806a4..31c669a921 100644
--- a/templates/base/footer.tmpl
+++ b/templates/base/footer.tmpl
@@ -26,6 +26,8 @@
{{end}}
{{end}}
<script src="{{AssetUrlPrefix}}/js/index.js?v={{AssetVersion}}" onerror="alert('Failed to load asset files from ' + this.src + '. Please make sure the asset files can be accessed.')"></script>
-{{template "custom/footer" .}}
+
+ {{template "custom/footer" .}}
+ {{ctx.DataRaceCheck $.Context}}
</body>
</html>
diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl
index 4858d0b7de..8eebaebd70 100644
--- a/templates/base/head.tmpl
+++ b/templates/base/head.tmpl
@@ -1,5 +1,5 @@
<!DOCTYPE html>
-<html lang="{{.locale.Lang}}" class="theme-{{if .SignedUser.Theme}}{{.SignedUser.Theme}}{{else}}{{DefaultTheme}}{{end}}">
+<html lang="{{ctx.Locale.Lang}}" class="theme-{{if .SignedUser.Theme}}{{.SignedUser.Theme}}{{else}}{{DefaultTheme}}{{end}}">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{if .Title}}{{.Title | RenderEmojiPlain}} - {{end}}{{if .Repository.Name}}{{.Repository.Name}} - {{end}}{{AppName}}</title>
@@ -28,7 +28,7 @@
{{if .PageIsUserProfile}}
<meta property="og:title" content="{{.ContextUser.DisplayName}}">
<meta property="og:type" content="profile">
- <meta property="og:image" content="{{.ContextUser.AvatarLink $.Context}}">
+ <meta property="og:image" content="{{.ContextUser.AvatarLink ctx}}">
<meta property="og:url" content="{{.ContextUser.HTMLURL}}">
{{if .ContextUser.Description}}
<meta property="og:description" content="{{.ContextUser.Description}}">
@@ -48,10 +48,10 @@
{{end}}
{{end}}
<meta property="og:type" content="object">
- {{if (.Repository.AvatarLink $.Context)}}
- <meta property="og:image" content="{{.Repository.AvatarLink $.Context}}">
+ {{if (.Repository.AvatarLink ctx)}}
+ <meta property="og:image" content="{{.Repository.AvatarLink ctx}}">
{{else}}
- <meta property="og:image" content="{{.Repository.Owner.AvatarLink $.Context}}">
+ <meta property="og:image" content="{{.Repository.Owner.AvatarLink ctx}}">
{{end}}
{{else}}
<meta property="og:title" content="{{AppName}}">
@@ -65,10 +65,11 @@
{{template "custom/header" .}}
</head>
<body>
+ {{ctx.DataRaceCheck $.Context}}
{{template "custom/body_outer_pre" .}}
<div class="full height">
- <noscript>{{.locale.Tr "enable_javascript"}}</noscript>
+ <noscript>{{ctx.Locale.Tr "enable_javascript"}}</noscript>
{{template "custom/body_inner_pre" .}}