forked from kevadesu/forgejo
Merge pull request 'Rewrite OpenGraph Header' (#6447) from JakobDev/forgejo:ogrewrite into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6447 Reviewed-by: Otto <otto@codeberg.org>
This commit is contained in:
commit
b59522f0b3
9 changed files with 49 additions and 59 deletions
|
@ -1,12 +1,24 @@
|
|||
{{- /* og:description - a one to two sentence description of your object, maybe it only needs at most 300 bytes */ -}}
|
||||
{{- /* See https://ogp.me for specification */ -}}
|
||||
{{if .OpenGraphTitle}}
|
||||
<meta property="og:title" content="{{.OpenGraphTitle}}">
|
||||
{{else if .Title}}
|
||||
<meta property="og:title" content="{{.Title}}">
|
||||
{{else}}
|
||||
<meta property="og:title" content="{{AppDisplayName}}">
|
||||
{{end}}
|
||||
{{if .OpenGraphDescription}}
|
||||
<meta property="og:description" content="{{.OpenGraphDescription}}">
|
||||
{{- /* og:description - a one to two sentence description of your object, maybe it only needs at most 300 bytes */ -}}
|
||||
{{if and .OpenGraphDescription (not .OpenGraphNoDescription)}}
|
||||
<meta property="og:description" content="{{StringUtils.EllipsisString .OpenGraphDescription 300}}">
|
||||
{{end}}
|
||||
{{if .OpenGraphURL}}
|
||||
<meta property="og:url" content="{{.OpenGraphURL}}">
|
||||
{{else}}
|
||||
<meta property="og:url" content="{{AppUrl}}{{.Link}}">
|
||||
{{end}}
|
||||
{{if .OpenGraphType}}
|
||||
<meta property="og:type" content="{{.OpenGraphType}}">
|
||||
{{else}}
|
||||
<meta property="og:type" content="website">
|
||||
{{end}}
|
||||
{{if .OpenGraphImageURL}}
|
||||
<meta property="og:image" content="{{.OpenGraphImageURL}}">
|
||||
|
@ -19,62 +31,7 @@
|
|||
{{if .OpenGraphImageAltText}}
|
||||
<meta property="og:image:alt" content="{{.OpenGraphImageAltText}}">
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{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 if .Pages}}
|
||||
<meta property="og:title" content="{{.Title}}">
|
||||
<meta property="og:url" content="{{AppUrl}}{{.Link}}">
|
||||
{{if .Repository.Description}}
|
||||
<meta property="og:description" content="{{StringUtils.EllipsisString .Repository.Description 300}}">
|
||||
{{end}}
|
||||
{{else}}
|
||||
{{if not .OpenGraphTitle}}
|
||||
<meta property="og:title" content="{{.Repository.Name}}">
|
||||
{{end}}
|
||||
{{if not .OpenGraphURL}}
|
||||
<meta property="og:url" content="{{.Repository.HTMLURL}}">
|
||||
{{end}}
|
||||
{{if and (.Repository.Description) (not .OpenGraphDescription)}}
|
||||
<meta property="og:description" content="{{StringUtils.EllipsisString .Repository.Description 300}}">
|
||||
{{end}}
|
||||
{{end}}
|
||||
<meta property="og:type" content="object">
|
||||
{{if and (not .Issue) (not .OpenGraphImageURL)}}
|
||||
{{if (.Repository.AvatarLink ctx)}}
|
||||
<meta property="og:image" content="{{.Repository.AvatarLink ctx}}">
|
||||
{{else}}
|
||||
<meta property="og:image" content="{{.Repository.Owner.AvatarLink ctx}}">
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{else}}
|
||||
<meta property="og:title" content="{{AppDisplayName}}">
|
||||
<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}}">
|
||||
<meta property="og:image" content="{{AssetUrlPrefix}}/img/logo.png">
|
||||
{{end}}
|
||||
<meta property="og:site_name" content="{{AppDisplayName}}">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue