mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-09-12 01:41:32 +02:00
- Backport of #2094 - It's possible that `PageIsDiff` is set but not `Commit` resulting in a NPE in the template. This can happen when the requested commit doesn't exist. - Regression ofc802c46a9b
&5743d7cb5b
- Added 'hacky' integration test. (cherry picked from commit8db2d5e4a7
)
48 lines
2.1 KiB
Go HTML Template
48 lines
2.1 KiB
Go HTML Template
{{- /* 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="{{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="{{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 .Commit}}
|
|
{{- $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="{{StringUtils.EllipsisString .Repository.Description 300}}">
|
|
{{end}}
|
|
{{end}}
|
|
<meta property="og:type" content="object">
|
|
{{if (.Repository.AvatarLink ctx)}}
|
|
<meta property="og:image" content="{{.Repository.AvatarLink ctx}}">
|
|
{{else}}
|
|
<meta property="og:image" content="{{.Repository.Owner.AvatarLink ctx}}">
|
|
{{end}}
|
|
{{else}}
|
|
<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:description" content="{{MetaDescription}}">
|
|
{{end}}
|
|
<meta property="og:site_name" content="{{AppName}}">
|