summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models/issues/issue.go14
-rw-r--r--options/locale/locale_en-US.ini2
-rw-r--r--routers/web/repo/card.go31
-rw-r--r--routers/web/repo/issue.go2
-rw-r--r--routers/web/repo/release.go1
-rw-r--r--services/context/repo.go5
-rw-r--r--templates/base/head_opengraph.tmpl13
7 files changed, 35 insertions, 33 deletions
diff --git a/models/issues/issue.go b/models/issues/issue.go
index 17391ffe6c..fbbc4828a2 100644
--- a/models/issues/issue.go
+++ b/models/issues/issue.go
@@ -416,20 +416,6 @@ func (issue *Issue) SummaryCardURL() string {
return fmt.Sprintf("%s/summary-card", issue.HTMLURL())
}
-func (issue *Issue) SummaryCardSize() (int, int) {
- return 1200, 600
-}
-
-func (issue *Issue) SummaryCardWidth() int {
- width, _ := issue.SummaryCardSize()
- return width
-}
-
-func (issue *Issue) SummaryCardHeight() int {
- _, height := issue.SummaryCardSize()
- return height
-}
-
// Link returns the issue's relative URL.
func (issue *Issue) Link() string {
var path string
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index 3a1639db7e..40ed989e21 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -1148,6 +1148,7 @@ blame_prior = View blame prior to this change
blame.ignore_revs = Ignoring revisions in <a href="%s">.git-blame-ignore-revs</a>. Click <a href="%s">here to bypass</a> and see the normal blame view.
blame.ignore_revs.failed = Failed to ignore revisions in <a href="%s">.git-blame-ignore-revs</a>.
author_search_tooltip = Shows a maximum of 30 users
+summary_card_alt = Summary card of repository %s
tree_path_not_found_commit = Path %[1]s doesn't exist in commit %[2]s
tree_path_not_found_branch = Path %[1]s doesn't exist in branch %[2]s
@@ -2740,6 +2741,7 @@ release.asset_name = Asset name
release.asset_external_url = External URL
release.add_external_asset = Add external asset
release.invalid_external_url = Invalid external URL: "%s"
+release.summary_card_alt = Summary card of an release titled "%s" in repository %s
branch.name = Branch name
branch.already_exists = A branch named "%s" already exists.
diff --git a/routers/web/repo/card.go b/routers/web/repo/card.go
index 3564d6486c..0afdf98d0a 100644
--- a/routers/web/repo/card.go
+++ b/routers/web/repo/card.go
@@ -25,7 +25,7 @@ import (
"code.gitea.io/gitea/services/context"
)
-// drawUser draws a user avator in a summary card
+// drawUser draws a user avatar in a summary card
func drawUser(ctx *context.Context, card *card.Card, user *user_model.User) error {
if user.UseCustomAvatar {
posterAvatarPath := user.CustomAvatarRelativePath()
@@ -50,6 +50,7 @@ func drawUser(ctx *context.Context, card *card.Card, user *user_model.User) erro
// drawRepoIcon draws the repo icon in a summary card
func drawRepoIcon(ctx *context.Context, card *card.Card, repo *repo_model.Repository) error {
repoAvatarPath := repo.CustomAvatarRelativePath()
+
if repoAvatarPath != "" {
repoAvatarFile, err := storage.RepoAvatars.Open(repoAvatarPath)
if err != nil {
@@ -61,21 +62,21 @@ func drawRepoIcon(ctx *context.Context, card *card.Card, repo *repo_model.Reposi
}
card.DrawImage(repoAvatarImage)
return nil
- } else {
- // If the repo didn't have an avatar, fallback to the repo owner's avatar for the right-hand-side icon
- err := repo.LoadOwner(ctx)
+ }
+
+ // If the repo didn't have an avatar, fallback to the repo owner's avatar for the right-hand-side icon
+ err := repo.LoadOwner(ctx)
+ if err != nil {
+ return err
+ }
+ if repo.Owner != nil {
+ err = drawUser(ctx, card, repo.Owner)
if err != nil {
return err
}
- if repo.Owner != nil {
- err = drawUser(ctx, card, repo.Owner)
- if err != nil {
- return err
- }
- }
-
- return nil
}
+
+ return nil
}
// hexToColor converts a hex color to a go color
@@ -227,7 +228,7 @@ func drawRepoSummaryCard(ctx *context.Context, repo *repo_model.Repository) (*ca
}
func drawIssueSummaryCard(ctx *context.Context, issue *issue_model.Issue) (*card.Card, error) {
- width, height := issue.SummaryCardSize()
+ width, height := card.DefaultSize()
mainCard, err := card.NewCard(width, height)
if err != nil {
return nil, err
@@ -397,7 +398,7 @@ func drawReleaseSummaryCard(ctx *context.Context, release *repo_model.Release) (
return mainCard, nil
}
-// checkCardCache checks if a card in cahce and serves it
+// checkCardCache checks if a card in cache and serves it
func checkCardCache(ctx *context.Context, cacheKey string) bool {
cache := cache.GetCache()
pngData, ok := cache.Get(cacheKey).([]byte)
@@ -414,7 +415,7 @@ func checkCardCache(ctx *context.Context, cacheKey string) bool {
return false
}
-// serveCard server a Crad to the user adds it to the cache
+// serveCard server a Card to the user adds it to the cache
func serveCard(ctx *context.Context, card *card.Card, cacheKey string) {
cache := cache.GetCache()
diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go
index b86749ec69..0248485dac 100644
--- a/routers/web/repo/issue.go
+++ b/routers/web/repo/issue.go
@@ -2055,6 +2055,8 @@ func ViewIssue(ctx *context.Context) {
ctx.Data["RefEndName"] = git.RefName(issue.Ref).ShortName()
ctx.Data["NewPinAllowed"] = pinAllowed
ctx.Data["PinEnabled"] = setting.Repository.Issue.MaxPinned != 0
+ ctx.Data["OpenGraphImageURL"] = issue.SummaryCardURL()
+ ctx.Data["OpenGraphImageAltText"] = ctx.Tr("repo.issues.summary_card_alt", issue.Title, issue.Repo.FullName())
prepareHiddenCommentType(ctx)
if ctx.Written() {
diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go
index ae7a645791..1791788743 100644
--- a/routers/web/repo/release.go
+++ b/routers/web/repo/release.go
@@ -379,6 +379,7 @@ func SingleRelease(ctx *context.Context) {
ctx.Data["OpenGraphDescription"] = base.EllipsisString(release.Note, 300)
ctx.Data["OpenGraphURL"] = release.HTMLURL()
ctx.Data["OpenGraphImageURL"] = release.SummaryCardURL()
+ ctx.Data["OpenGraphImageAltText"] = ctx.Tr("repo.release.summary_card_alt", release.DisplayName(), release.Repo.FullName())
ctx.HTML(http.StatusOK, tplReleasesList)
}
diff --git a/services/context/repo.go b/services/context/repo.go
index de4e33eb1f..462d843bfc 100644
--- a/services/context/repo.go
+++ b/services/context/repo.go
@@ -25,6 +25,7 @@ import (
unit_model "code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/cache"
+ "code.gitea.io/gitea/modules/card"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/gitrepo"
code_indexer "code.gitea.io/gitea/modules/indexer/code"
@@ -632,7 +633,11 @@ func RepoAssignment(ctx *Context) context.CancelFunc {
ctx.Data["IsStaringRepo"] = repo_model.IsStaring(ctx, ctx.Doer.ID, repo.ID)
}
+ cardWidth, cardHeight := card.DefaultSize()
ctx.Data["OpenGraphImageURL"] = repo.SummaryCardURL()
+ ctx.Data["OpenGraphImageWidth"] = cardWidth
+ ctx.Data["OpenGraphImageHeight"] = cardHeight
+ ctx.Data["OpenGraphImageAltText"] = ctx.Tr("repo.summary_card_alt", repo.FullName())
if repo.IsFork {
RetrieveBaseRepo(ctx, repo)
diff --git a/templates/base/head_opengraph.tmpl b/templates/base/head_opengraph.tmpl
index bcdfa25695..692f1797b6 100644
--- a/templates/base/head_opengraph.tmpl
+++ b/templates/base/head_opengraph.tmpl
@@ -10,6 +10,15 @@
{{end}}
{{if .OpenGraphImageURL}}
<meta property="og:image" content="{{.OpenGraphImageURL}}">
+ {{if .OpenGraphImageWidth}}
+ <meta property="og:image:width" content="{{.OpenGraphImageWidth}}">
+ {{end}}
+ {{if .OpenGraphImageHeight}}
+ <meta property="og:image:height" content="{{.OpenGraphImageHeight}}">
+ {{end}}
+ {{if .OpenGraphImageAltText}}
+ <meta property="og:image:alt" content="{{.OpenGraphImageAltText}}">
+ {{end}}
{{end}}
{{if .PageIsUserProfile}}
<meta property="og:title" content="{{.ContextUser.DisplayName}}">
@@ -26,10 +35,6 @@
{{if .Issue.Content}}
<meta property="og:description" content="{{StringUtils.EllipsisString .Issue.Content 300}}">
{{end}}
- <meta property="og:image" content="{{.Issue.SummaryCardURL}}">
- <meta property="og:image:width" content="{{.Issue.SummaryCardWidth}}">
- <meta property="og:image:height" content="{{.Issue.SummaryCardHeight}}">
- <meta property="og:image:alt" content="{{ctx.Locale.Tr "repo.issues.summary_card_alt" .Issue.Title .Repository.FullName}}">
{{else if or .PageIsDiff .IsViewFile}}
<meta property="og:title" content="{{.Title}}">
<meta property="og:url" content="{{AppUrl}}{{.Link}}">