Files
teahub/gitea/custom/templates/base/head_opengraph.tmpl
T
teahubxyzandClaude Opus 5.5 b805d7bd5e Link previews: absolute og:image card for site pages
Gitea 28.0.0's head_opengraph.tmpl. Pages that aren't a repository or a profile now point
og:image at the absolute /assets/img/og-card.png (WhatsApp needs an absolute URL), give its
size and alt text, and ask for the large card with twitter:card summary_large_image.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XvDrpBDoAJjW8z1kaa3GAa
2026-10-16 10:28:36 +00:00

52 lines
2.4 KiB
Cheetah

{{- /* 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 ctx}}">
{{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 ctx}}">
{{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="{{ctx.AppFullLink $.Link}}">
{{if and .PageIsDiff .Commit}}
{{- $commitMessageBody := .Commit.MessageBody -}}
{{- 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 ctx}}">
{{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}}
{{/* Teahub: the 1200x630 card at an absolute URL (WhatsApp needs one), its size, and the large-card layout. */}}
<meta property="og:title" content="{{AppName}}">
<meta property="og:type" content="website">
<meta property="og:image" content="{{ctx.AppFullLink "/assets/img/og-card.png"}}">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="Teahub: Git + Tea + Time, beside a cup of green tea">
<meta property="og:url" content="{{ctx.AppFullLink}}">
<meta property="og:description" content="{{MetaDescription}}">
<meta name="twitter:card" content="summary_large_image">
{{end}}
<meta property="og:site_name" content="{{AppName}}">