From e71eb8930a5d0f60874b038c223498b41ad65592 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 1 Mar 2024 15:11:51 +0800 Subject: Refactor some Str2html code (#29397) This PR touches the most interesting part of the "template refactoring". 1. Unclear variable type. Especially for "web/feed/convert.go": sometimes it uses text, sometimes it uses HTML. 2. Assign text content to "RenderedContent" field, for example: ` project.RenderedContent = project.Description` in web/org/projects.go 3. Assign rendered content to text field, for example: `r.Note = rendered content` in web/repo/release.go 4. (possible) Incorrectly calling `{{Str2html .PackageDescriptor.Metadata.ReleaseNotes}}` in package/content/nuget.tmpl, I guess the name Str2html misleads developers to use it to "render string to html", but it only sanitizes. if ReleaseNotes really contains HTML, then this is not a problem. --- templates/mail/release.tmpl | 2 +- templates/org/header.tmpl | 2 +- templates/org/home.tmpl | 2 +- templates/package/content/nuget.tmpl | 2 +- templates/projects/list.tmpl | 2 +- templates/projects/view.tmpl | 2 +- templates/repo/diff/comments.tmpl | 2 +- templates/repo/issue/milestone_issues.tmpl | 2 +- templates/repo/issue/milestones.tmpl | 2 +- templates/repo/issue/view_content.tmpl | 2 +- templates/repo/issue/view_content/attachments.tmpl | 4 ++-- templates/repo/issue/view_content/comments.tmpl | 6 +++--- templates/repo/issue/view_content/conversation.tmpl | 2 +- templates/repo/release/list.tmpl | 2 +- templates/shared/user/profile_big_avatar.tmpl | 2 +- templates/user/dashboard/milestones.tmpl | 2 +- templates/user/profile.tmpl | 2 +- 17 files changed, 20 insertions(+), 20 deletions(-) (limited to 'templates') diff --git a/templates/mail/release.tmpl b/templates/mail/release.tmpl index 62a16573c6..90a3caa4c5 100644 --- a/templates/mail/release.tmpl +++ b/templates/mail/release.tmpl @@ -22,7 +22,7 @@ {{.locale.Tr "mail.release.note"}}
{{- if eq .Release.RenderedNote ""}} {{else}} - {{.Release.RenderedNote | Str2html}} + {{.Release.RenderedNote}} {{end -}}



diff --git a/templates/org/header.tmpl b/templates/org/header.tmpl index 8423fd7d3b..efbbc43b1d 100644 --- a/templates/org/header.tmpl +++ b/templates/org/header.tmpl @@ -18,7 +18,7 @@ {{end}} - {{if .RenderedDescription}}
{{.RenderedDescription | Str2html}}
{{end}} + {{if .RenderedDescription}}
{{.RenderedDescription}}
{{end}}
{{if .Org.Location}}
{{svg "octicon-location"}} {{.Org.Location}}
{{end}} {{if .Org.Website}}
{{svg "octicon-link"}} {{.Org.Website}}
{{end}} diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl index 4e33b1af72..892ba0da5b 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -6,7 +6,7 @@
{{if .ProfileReadme}} -
{{.ProfileReadme | Str2html}}
+
{{.ProfileReadme}}
{{end}} {{template "explore/repo_search" .}} {{template "explore/repo_list" .}} diff --git a/templates/package/content/nuget.tmpl b/templates/package/content/nuget.tmpl index f84288629d..2008cf4cc8 100644 --- a/templates/package/content/nuget.tmpl +++ b/templates/package/content/nuget.tmpl @@ -20,7 +20,7 @@

{{ctx.Locale.Tr "packages.about"}}

{{if .PackageDescriptor.Metadata.Description}}{{.PackageDescriptor.Metadata.Description}}{{end}} - {{if .PackageDescriptor.Metadata.ReleaseNotes}}{{Str2html .PackageDescriptor.Metadata.ReleaseNotes}}{{end}} + {{if .PackageDescriptor.Metadata.ReleaseNotes}}{{.PackageDescriptor.Metadata.ReleaseNotes}}{{end}}
{{end}} diff --git a/templates/projects/list.tmpl b/templates/projects/list.tmpl index cbff82dd70..30fbd498a4 100644 --- a/templates/projects/list.tmpl +++ b/templates/projects/list.tmpl @@ -75,7 +75,7 @@
{{if .Description}}
- {{.RenderedContent|Str2html}} + {{.RenderedContent}}
{{end}} diff --git a/templates/projects/view.tmpl b/templates/projects/view.tmpl index b3ad03c354..3792ccca0e 100644 --- a/templates/projects/view.tmpl +++ b/templates/projects/view.tmpl @@ -58,7 +58,7 @@ {{end}}
-
{{$.Project.RenderedContent|Str2html}}
+
{{$.Project.RenderedContent}}
diff --git a/templates/repo/diff/comments.tmpl b/templates/repo/diff/comments.tmpl index e567417fa6..e00487a22c 100644 --- a/templates/repo/diff/comments.tmpl +++ b/templates/repo/diff/comments.tmpl @@ -55,7 +55,7 @@
{{if .RenderedContent}} - {{.RenderedContent|Str2html}} + {{.RenderedContent}} {{else}} {{ctx.Locale.Tr "repo.issues.no_content"}} {{end}} diff --git a/templates/repo/issue/milestone_issues.tmpl b/templates/repo/issue/milestone_issues.tmpl index d9495d9b77..35a8a77680 100644 --- a/templates/repo/issue/milestone_issues.tmpl +++ b/templates/repo/issue/milestone_issues.tmpl @@ -22,7 +22,7 @@
{{if .Milestone.RenderedContent}}
- {{.Milestone.RenderedContent|Str2html}} + {{.Milestone.RenderedContent}}
{{end}}
diff --git a/templates/repo/issue/milestones.tmpl b/templates/repo/issue/milestones.tmpl index 698e3fffba..363ba7e3a2 100644 --- a/templates/repo/issue/milestones.tmpl +++ b/templates/repo/issue/milestones.tmpl @@ -82,7 +82,7 @@
{{if .Content}}
- {{.RenderedContent|Str2html}} + {{.RenderedContent}}
{{end}} diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index b5441872a3..ee824b76b1 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -54,7 +54,7 @@
{{if .Issue.RenderedContent}} - {{.Issue.RenderedContent|Str2html}} + {{.Issue.RenderedContent}} {{else}} {{ctx.Locale.Tr "repo.issues.no_content"}} {{end}} diff --git a/templates/repo/issue/view_content/attachments.tmpl b/templates/repo/issue/view_content/attachments.tmpl index 1fb6f2f2c2..58f4c702b3 100644 --- a/templates/repo/issue/view_content/attachments.tmpl +++ b/templates/repo/issue/view_content/attachments.tmpl @@ -8,7 +8,7 @@
{{if FilenameIsImage .Name}} - {{if not (StringUtils.Contains $.Content .UUID)}} + {{if not (StringUtils.Contains (StringUtils.ToString $.Content) .UUID)}} {{$hasThumbnails = true}} {{end}} {{svg "octicon-file"}} @@ -29,7 +29,7 @@
{{- range .Attachments -}} {{if FilenameIsImage .Name}} - {{if not (StringUtils.Contains $.Content .UUID)}} + {{if not (StringUtils.Contains (StringUtils.ToString $.Content) .UUID)}} {{.Name}} diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 562e44c791..36ef5751ae 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -61,7 +61,7 @@
{{if .RenderedContent}} - {{.RenderedContent|Str2html}} + {{.RenderedContent}} {{else}} {{ctx.Locale.Tr "repo.issues.no_content"}} {{end}} @@ -432,7 +432,7 @@
{{if .RenderedContent}} - {{.RenderedContent|Str2html}} + {{.RenderedContent}} {{else}} {{ctx.Locale.Tr "repo.issues.no_content"}} {{end}} @@ -631,7 +631,7 @@
{{if .RenderedContent}} - {{.RenderedContent|Str2html}} + {{.RenderedContent}} {{else}} {{ctx.Locale.Tr "repo.issues.no_content"}} {{end}} diff --git a/templates/repo/issue/view_content/conversation.tmpl b/templates/repo/issue/view_content/conversation.tmpl index 1bad0e9b55..1afc744aee 100644 --- a/templates/repo/issue/view_content/conversation.tmpl +++ b/templates/repo/issue/view_content/conversation.tmpl @@ -87,7 +87,7 @@
{{if .RenderedContent}} - {{.RenderedContent|Str2html}} + {{.RenderedContent}} {{else}} {{ctx.Locale.Tr "repo.issues.no_content"}} {{end}} diff --git a/templates/repo/release/list.tmpl b/templates/repo/release/list.tmpl index 5b747c2bf9..7f38fa3ff0 100644 --- a/templates/repo/release/list.tmpl +++ b/templates/repo/release/list.tmpl @@ -58,7 +58,7 @@ {{end}}

- {{Str2html $release.Note}} + {{$release.RenderedNote}}
diff --git a/templates/shared/user/profile_big_avatar.tmpl b/templates/shared/user/profile_big_avatar.tmpl index 19a3b25cc5..88d3b9a6e5 100644 --- a/templates/shared/user/profile_big_avatar.tmpl +++ b/templates/shared/user/profile_big_avatar.tmpl @@ -70,7 +70,7 @@ {{end}} {{if $.RenderedDescription}}
  • -
    {{$.RenderedDescription|Str2html}}
    +
    {{$.RenderedDescription}}
  • {{end}} {{range .OpenIDs}} diff --git a/templates/user/dashboard/milestones.tmpl b/templates/user/dashboard/milestones.tmpl index 1829021ff4..737a0f7e2b 100644 --- a/templates/user/dashboard/milestones.tmpl +++ b/templates/user/dashboard/milestones.tmpl @@ -141,7 +141,7 @@
    {{if .Content}}
    - {{.RenderedContent|Str2html}} + {{.RenderedContent}}
    {{end}} diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 426b5f042a..37590fc2fa 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -29,7 +29,7 @@ {{else if eq .TabName "followers"}} {{template "repo/user_cards" .}} {{else if eq .TabName "overview"}} -
    {{.ProfileReadme | Str2html}}
    +
    {{.ProfileReadme}}
    {{else}} {{template "explore/repo_search" .}} {{template "explore/repo_list" .}} -- cgit v1.2.3