diff --git a/options/locale_next/locale_en-US.json b/options/locale_next/locale_en-US.json index b1c98e4551..a551db87dc 100644 --- a/options/locale_next/locale_en-US.json +++ b/options/locale_next/locale_en-US.json @@ -102,5 +102,6 @@ "admin.dashboard.cleanup_offline_runners": "Cleanup offline runners", "settings.visibility.description": "Profile visibility affects others' ability to access your non-private repositories. Learn more", "avatar.constraints_hint": "Custom avatar may not exceed %[1]s in size or be larger than %[2]dx%[3]d pixels", + "og.repo.summary_card.alt_description": "Summary card of repository %[1]s, described as: %[2]s", "meta.last_line": "Thank you for translating Forgejo! This line isn't seen by the users but it serves other purposes in the translation management. You can place a fun fact in the translation instead of translating it." } diff --git a/services/context/repo.go b/services/context/repo.go index cce3a5fa70..c8876d7166 100644 --- a/services/context/repo.go +++ b/services/context/repo.go @@ -644,7 +644,11 @@ func RepoAssignment(ctx *Context) context.CancelFunc { 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 util.IsEmptyString(repo.Description) { + ctx.Data["OpenGraphImageAltText"] = ctx.Tr("repo.summary_card_alt", repo.FullName()) + } else { + ctx.Data["OpenGraphImageAltText"] = ctx.Tr("og.repo.summary_card.alt_description", repo.FullName(), repo.Description) + } if repo.IsFork { RetrieveBaseRepo(ctx, repo) diff --git a/tests/integration/opengraph_test.go b/tests/integration/opengraph_test.go index 56fbedd351..aa6d8daf5c 100644 --- a/tests/integration/opengraph_test.go +++ b/tests/integration/opengraph_test.go @@ -98,7 +98,7 @@ func TestOpenGraphProperties(t *testing.T) { "og:url": setting.AppURL + "/user27/repo49/src/branch/master/test/test.txt", "og:type": "object", "og:image": setting.AppURL + "user27/repo49/-/summary-card", - "og:image:alt": "Summary card of repository user27/repo49", + "og:image:alt": "Summary card of repository user27/repo49, described as: A wonderful repository with more than just a README.md", "og:image:width": "1200", "og:image:height": "600", "og:site_name": siteName, @@ -141,7 +141,7 @@ func TestOpenGraphProperties(t *testing.T) { "og:description": "A wonderful repository with more than just a README.md", "og:type": "object", "og:image": setting.AppURL + "user27/repo49/-/summary-card", - "og:image:alt": "Summary card of repository user27/repo49", + "og:image:alt": "Summary card of repository user27/repo49, described as: A wonderful repository with more than just a README.md", "og:image:width": "1200", "og:image:height": "600", "og:site_name": siteName,