loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Breaking summary for template refactoring (#29395)

https://github.com/go-gitea/gitea/pull/29395
(cherry picked from commit e71b69257c38178eed9ccd0b62a5ae47d67858d4)

authored by

wxiaoguang and committed by
Earl Warren
99b1a39a fa6627fa

+31 -31
+8 -8
docs/content/administration/mail-templates.en-us.md
··· 259 259 The template system contains several functions that can be used to further process and format 260 260 the messages. Here's a list of some of them: 261 261 262 - | Name | Parameters | Available | Usage | 263 - | ---------------- | ----------- | --------- |-----------------------------------------------------------------------------| 264 - | `AppUrl` | - | Any | Gitea's URL | 265 - | `AppName` | - | Any | Set from `app.ini`, usually "Gitea" | 266 - | `AppDomain` | - | Any | Gitea's host name | 267 - | `EllipsisString` | string, int | Any | Truncates a string to the specified length; adds ellipsis as needed | 268 - | `SanitizeHTML` | string | Body only | Sanitizes text by removing any dangerous HTML tags from it. | 269 - | `SafeHTML` | string | Body only | Takes the input as HTML; can be used for `.ReviewComments.RenderedContent`. | 262 + | Name | Parameters | Available | Usage | 263 + | ---------------- | ----------- | --------- | ------------------------------------------------------------------- | 264 + | `AppUrl` | - | Any | Gitea's URL | 265 + | `AppName` | - | Any | Set from `app.ini`, usually "Gitea" | 266 + | `AppDomain` | - | Any | Gitea's host name | 267 + | `EllipsisString` | string, int | Any | Truncates a string to the specified length; adds ellipsis as needed | 268 + | `SanitizeHTML` | string | Body only | Sanitizes text by removing any dangerous HTML tags from it | 269 + | `SafeHTML` | string | Body only | Takes the input as HTML, can be used for outputing raw HTML content | 270 270 271 271 These are _functions_, not metadata, so they have to be used: 272 272
+8 -8
docs/content/administration/mail-templates.zh-cn.md
··· 242 242 243 243 模板系统包含一些函数,可用于进一步处理和格式化消息。以下是其中一些函数的列表: 244 244 245 - | 函数名 | 参数 | 可用于 | 用法 | 246 - |------------------| ----------- | ------------ |---------------------------------------------------------| 247 - | `AppUrl` | - | 任何地方 | Gitea 的 URL | 248 - | `AppName` | - | 任何地方 | 从 `app.ini` 中设置,通常为 "Gitea" | 249 - | `AppDomain` | - | 任何地方 | Gitea 的主机名 | 250 - | `EllipsisString` | string, int | 任何地方 | 将字符串截断为指定长度;根据需要添加省略号 | 251 - | `SanitizeHTML` | string | 仅正文部分 | 通过删除其中的危险 HTML 标签对文本进行清理 | 252 - | `SafeHTML` | string | 仅正文部分 | 将输入作为 HTML 处理;可用于 `.ReviewComments.RenderedContent` 等字段 | 245 + | 函数名 | 参数 | 可用于 | 用法 | 246 + |------------------| ----------- | ------------ | ------------------------------ | 247 + | `AppUrl` | - | 任何地方 | Gitea 的 URL | 248 + | `AppName` | - | 任何地方 | 从 `app.ini` 中设置,通常为 "Gitea" | 249 + | `AppDomain` | - | 任何地方 | Gitea 的主机名 | 250 + | `EllipsisString` | string, int | 任何地方 | 将字符串截断为指定长度;根据需要添加省略号 | 251 + | `SanitizeHTML` | string | 仅正文部分 | 通过删除其中的危险 HTML 标签对文本进行清理 | 252 + | `SafeHTML` | string | 仅正文部分 | 将输入作为 HTML 处理;可用于输出原始的 HTML 内容 | 253 253 254 254 这些都是 _函数_,而不是元数据,因此必须按以下方式使用: 255 255
+14 -14
modules/templates/mailer.go
··· 5 5 6 6 import ( 7 7 "context" 8 + "fmt" 8 9 "html/template" 9 10 "regexp" 10 11 "strings" ··· 33 34 } 34 35 } 35 36 36 - func buildSubjectBodyTemplate(stpl *texttmpl.Template, btpl *template.Template, name string, content []byte) { 37 + func buildSubjectBodyTemplate(stpl *texttmpl.Template, btpl *template.Template, name string, content []byte) error { 37 38 // Split template into subject and body 38 39 var subjectContent []byte 39 40 bodyContent := content ··· 42 43 subjectContent = content[0:loc[0]] 43 44 bodyContent = content[loc[1]:] 44 45 } 45 - if _, err := stpl.New(name). 46 - Parse(string(subjectContent)); err != nil { 47 - log.Error("Failed to parse template [%s/subject]: %v", name, err) 48 - if !setting.IsProd { 49 - log.Fatal("Please fix the mail template error") 50 - } 46 + if _, err := stpl.New(name).Parse(string(subjectContent)); err != nil { 47 + return fmt.Errorf("failed to parse template [%s/subject]: %w", name, err) 51 48 } 52 - if _, err := btpl.New(name). 53 - Parse(string(bodyContent)); err != nil { 54 - log.Error("Failed to parse template [%s/body]: %v", name, err) 55 - if !setting.IsProd { 56 - log.Fatal("Please fix the mail template error") 57 - } 49 + if _, err := btpl.New(name).Parse(string(bodyContent)); err != nil { 50 + return fmt.Errorf("failed to parse template [%s/body]: %w", name, err) 58 51 } 52 + return nil 59 53 } 60 54 61 55 // Mailer provides the templates required for sending notification mails. ··· 87 81 if firstRun { 88 82 log.Trace("Adding mail template %s: %s by %s", tmplName, assetPath, layerName) 89 83 } 90 - buildSubjectBodyTemplate(subjectTemplates, bodyTemplates, tmplName, content) 84 + if err = buildSubjectBodyTemplate(subjectTemplates, bodyTemplates, tmplName, content); err != nil { 85 + if firstRun { 86 + log.Fatal("Failed to parse mail template, err: %v", err) 87 + } else { 88 + log.Error("Failed to parse mail template, err: %v", err) 89 + } 90 + } 91 91 } 92 92 } 93 93
+1 -1
templates/mail/issue/default.tmpl
··· 65 65 {{$.locale.Tr "mail.issue.in_tree_path" .TreePath}} 66 66 <div class="review"> 67 67 <pre>{{.Patch}}</pre> 68 - <div>{{.RenderedContent | SafeHTML}}</div> 68 + <div>{{.RenderedContent}}</div> 69 69 </div> 70 70 {{end -}} 71 71 {{if eq .ActionName "push"}}