aboutsummaryrefslogtreecommitdiffstats
path: root/templates
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-09-03 09:43:29 +0800
committerGitHub <noreply@github.com>2023-09-03 01:43:29 +0000
commitc802c46a9beeaed44d41f50de31a4db146cdd8f7 (patch)
tree9492798f81da6949f23e4d1f79ed8528f226dac3 /templates
parent9a3de436f452144933888fb1e4f336efeb93293a (diff)
downloadgitea-c802c46a9beeaed44d41f50de31a4db146cdd8f7.tar.gz
gitea-c802c46a9beeaed44d41f50de31a4db146cdd8f7.zip
Refactor `og:description` to limit the max length (#26876)
1. The `og:description` should be "a one to two sentence description of your object" * It shouldn't output all the user inputted content -- it would be pretty huge. * Maybe it only needs at most 300 bytes. 2. Do not render commit message as HTML
Diffstat (limited to 'templates')
-rw-r--r--templates/base/head_opengraph.tmpl15
1 files changed, 10 insertions, 5 deletions
diff --git a/templates/base/head_opengraph.tmpl b/templates/base/head_opengraph.tmpl
index fc3958b6b6..19d924610c 100644
--- a/templates/base/head_opengraph.tmpl
+++ b/templates/base/head_opengraph.tmpl
@@ -1,29 +1,34 @@
+{{- /* og:description - a one to two sentence description of your object, maybe it only needs at most 300 bytes */ -}}
{{if .PageIsUserProfile}}
<meta property="og:title" content="{{.ContextUser.DisplayName}}">
<meta property="og:type" content="profile">
<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}}">
+ <meta property="og:description" content="{{StringUtils.EllipsisString .ContextUser.Description 300}}">
{{end}}
{{else if .Repository}}
{{if .Issue}}
<meta property="og:title" content="{{.Issue.Title}}">
<meta property="og:url" content="{{.Issue.HTMLURL}}">
{{if .Issue.Content}}
- <meta property="og:description" content="{{.Issue.Content}}">
+ <meta property="og:description" content="{{StringUtils.EllipsisString .Issue.Content 300}}">
{{end}}
{{else if or .PageIsDiff .IsViewFile}}
<meta property="og:title" content="{{.Title}}">
<meta property="og:url" content="{{AppUrl}}{{.Link}}">
- {{if and .PageIsDiff (IsMultilineCommitMessage .Commit.Message)}}
- <meta property="og:description" content="{{RenderCommitBody $.Context .Commit.Message $.RepoLink $.Repository.ComposeMetas}}">
+ {{if .PageIsDiff}}
+ {{- $commitMessageParts := StringUtils.Cut .Commit.Message "\n" -}}
+ {{- $commitMessageBody := index $commitMessageParts 1 -}}
+ {{- if $commitMessageBody -}}
+ <meta property="og:description" content="{{StringUtils.EllipsisString $commitMessageBody 300}}">
+ {{- end -}}
{{end}}
{{else}}
<meta property="og:title" content="{{.Repository.Name}}">
<meta property="og:url" content="{{.Repository.HTMLURL}}">
{{if .Repository.Description}}
- <meta property="og:description" content="{{.Repository.Description}}">
+ <meta property="og:description" content="{{StringUtils.EllipsisString .Repository.Description 300}}">
{{end}}
{{end}}
<meta property="og:type" content="object">