This commit is contained in:
JakobDev 2024-12-18 22:33:22 +01:00
parent aa64f6515c
commit 4568ebc913
No known key found for this signature in database
GPG key ID: 39DEF62C3ED6DC4C
4 changed files with 51 additions and 25 deletions

View file

@ -191,7 +191,7 @@ func (r *Release) Link() string {
// SummaryCardURL returns the absolute URL to an image providing a summary of the release
func (r *Release) SummaryCardURL() string {
return fmt.Sprintf("%s/releases/summary-card/%d", r.Repo.HTMLURL(), r.ID)
return fmt.Sprintf("%s/releases/summary-card/%s", r.Repo.HTMLURL(), util.PathEscapeSegments(r.TagName))
}
// DisplayName retruns the name of the release

View file

@ -494,7 +494,7 @@ func DrawIssueSummaryCard(ctx *context.Context) {
}
func DrawReleaseSummaryCard(ctx *context.Context) {
release, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":releaseID"))
release, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, ctx.Params("*"))
if err != nil {
if repo_model.IsErrReleaseNotExist(err) {
ctx.NotFound("", nil)

View file

@ -1299,7 +1299,7 @@ func registerRoutes(m *web.Route) {
m.Get("/latest", repo.LatestRelease)
m.Get(".rss", feedEnabled, repo.ReleasesFeedRSS)
m.Get(".atom", feedEnabled, repo.ReleasesFeedAtom)
m.Get("/summary-card/{releaseID}", repo.DrawReleaseSummaryCard)
m.Get("/summary-card/*", repo.DrawReleaseSummaryCard)
}, ctxDataSet("EnableFeed", setting.Other.EnableFeed),
repo.MustBeNotEmpty, context.RepoRefByType(context.RepoRefTag, true))
m.Get("/releases/attachments/{uuid}", repo.MustBeNotEmpty, repo.GetAttachment)

View file

@ -94,45 +94,71 @@ func TestOpenGraphProperties(t *testing.T) {
name: "file in repo",
url: "/user27/repo49/src/branch/master/test/test.txt",
expected: map[string]string{
"og:title": "repo49/test/test.txt at master",
"og:url": setting.AppURL + "/user27/repo49/src/branch/master/test/test.txt",
"og:type": "object",
"og:image": setting.AppURL + "user27/repo49/-/summary-card",
"og:site_name": siteName,
"og:title": "repo49/test/test.txt at master",
"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:width": "1200",
"og:image:height": "600",
"og:site_name": siteName,
},
},
{
name: "wiki page for repo without description",
url: "/user2/repo1/wiki/Page-With-Spaced-Name",
expected: map[string]string{
"og:title": "Page With Spaced Name",
"og:url": setting.AppURL + "/user2/repo1/wiki/Page-With-Spaced-Name",
"og:type": "object",
"og:image": setting.AppURL + "user2/repo1/-/summary-card",
"og:site_name": siteName,
"og:title": "Page With Spaced Name",
"og:url": setting.AppURL + "/user2/repo1/wiki/Page-With-Spaced-Name",
"og:type": "object",
"og:image": setting.AppURL + "user2/repo1/-/summary-card",
"og:image:alt": "Summary card of repository user2/repo1",
"og:image:width": "1200",
"og:image:height": "600",
"og:site_name": siteName,
},
},
{
name: "index page for repo without description",
url: "/user2/repo1",
expected: map[string]string{
"og:title": "repo1",
"og:url": setting.AppURL + "user2/repo1",
"og:type": "object",
"og:image": setting.AppURL + "user2/repo1/-/summary-card",
"og:site_name": siteName,
"og:title": "repo1",
"og:url": setting.AppURL + "user2/repo1",
"og:type": "object",
"og:image": setting.AppURL + "user2/repo1/-/summary-card",
"og:image:alt": "Summary card of repository user2/repo1",
"og:image:width": "1200",
"og:image:height": "600",
"og:site_name": siteName,
},
},
{
name: "index page for repo with description",
url: "/user27/repo49",
expected: map[string]string{
"og:title": "repo49",
"og:url": setting.AppURL + "user27/repo49",
"og:description": "A wonderful repository with more than just a README.md",
"og:type": "object",
"og:image": setting.AppURL + "user27/repo49/-/summary-card",
"og:site_name": siteName,
"og:title": "repo49",
"og:url": setting.AppURL + "user27/repo49",
"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:width": "1200",
"og:image:height": "600",
"og:site_name": siteName,
},
},
{
name: "release",
url: "/user2/repo1/releases/tag/v1.1",
expected: map[string]string{
"og:title": "testing-release - user2/repo1",
"og:url": setting.AppURL + "user2/repo1/releases/tag/v1.1",
"og:type": "object",
"og:image": setting.AppURL + "user2/repo1/releases/summary-card/v1.1",
"og:image:alt": "Summary card of an release titled \"testing-release\" in repository user2/repo1",
"og:image:width": "1200",
"og:image:height": "600",
"og:site_name": siteName,
},
},
}
@ -180,7 +206,7 @@ func TestOpenGraphSummaryCard(t *testing.T) {
},
{
name: "release",
url: "/user2/repo1/releases/summary-card/1",
url: "/user2/repo1/releases/summary-card/v1.1",
},
}