loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

Otto b59522f0 b5442431

+49 -59
+3
routers/web/home.go
··· 61 61 62 62 ctx.Data["PageIsHome"] = true 63 63 ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled 64 + 65 + ctx.Data["OpenGraphDescription"] = setting.UI.Meta.Description 66 + 64 67 ctx.HTML(http.StatusOK, tplHome) 65 68 } 66 69
+6
routers/web/org/home.go
··· 47 47 ctx.Data["PageIsUserProfile"] = true 48 48 ctx.Data["Title"] = org.DisplayName() 49 49 50 + ctx.Data["OpenGraphTitle"] = ctx.ContextUser.DisplayName() 51 + ctx.Data["OpenGraphType"] = "profile" 52 + ctx.Data["OpenGraphImageURL"] = ctx.ContextUser.AvatarLink(ctx) 53 + ctx.Data["OpenGraphURL"] = ctx.ContextUser.HTMLURL() 54 + ctx.Data["OpenGraphDescription"] = ctx.ContextUser.Description 55 + 50 56 var orderBy db.SearchOrderBy 51 57 sortOrder := ctx.FormString("sort") 52 58 if _, ok := repo_model.OrderByFlatMap[sortOrder]; !ok {
+4
routers/web/repo/commit.go
··· 419 419 } 420 420 } 421 421 422 + ctx.Data["OpenGraphTitle"] = commit.Summary() + " · " + base.ShortSha(commitID) 423 + ctx.Data["OpenGraphURL"] = fmt.Sprintf("%s/commit/%s", ctx.Repo.Repository.HTMLURL(), commitID) 424 + _, ctx.Data["OpenGraphDescription"], _ = strings.Cut(commit.Message(), "\n") 425 + 422 426 ctx.HTML(http.StatusOK, tplCommitPage) 423 427 } 424 428
+3
routers/web/repo/issue.go
··· 2070 2070 ctx.Data["RefEndName"] = git.RefName(issue.Ref).ShortName() 2071 2071 ctx.Data["NewPinAllowed"] = pinAllowed 2072 2072 ctx.Data["PinEnabled"] = setting.Repository.Issue.MaxPinned != 0 2073 + ctx.Data["OpenGraphTitle"] = issue.Title 2074 + ctx.Data["OpenGraphURL"] = issue.HTMLURL() 2075 + ctx.Data["OpenGraphDescription"] = issue.Content 2073 2076 ctx.Data["OpenGraphImageURL"] = issue.SummaryCardURL() 2074 2077 ctx.Data["OpenGraphImageAltText"] = ctx.Tr("repo.issues.summary_card_alt", issue.Title, issue.Repo.FullName()) 2075 2078
+4
routers/web/repo/view.go
··· 394 394 ctx.Data["FileName"] = blob.Name() 395 395 ctx.Data["RawFileLink"] = ctx.Repo.RepoLink + "/raw/" + ctx.Repo.BranchNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath) 396 396 397 + ctx.Data["OpenGraphTitle"] = ctx.Data["Title"] 398 + ctx.Data["OpenGraphURL"] = fmt.Sprintf("%s%s", setting.AppURL, ctx.Data["Link"]) 399 + ctx.Data["OpenGraphNoDescription"] = true 400 + 397 401 if entry.IsLink() { 398 402 _, link, err := entry.FollowLinks() 399 403 // Errors should be allowed, because this shouldn't
+3
routers/web/repo/wiki.go
··· 535 535 } 536 536 ctx.Data["Author"] = lastCommit.Author 537 537 538 + ctx.Data["OpenGraphTitle"] = ctx.Data["Title"] 539 + ctx.Data["OpenGraphURL"] = fmt.Sprintf("%s%s", setting.AppURL, ctx.Data["Link"]) 540 + 538 541 ctx.HTML(http.StatusOK, tplWikiView) 539 542 } 540 543
+6
routers/web/user/profile.go
··· 63 63 ctx.Data["Title"] = ctx.ContextUser.DisplayName() 64 64 ctx.Data["PageIsUserProfile"] = true 65 65 66 + ctx.Data["OpenGraphTitle"] = ctx.ContextUser.DisplayName() 67 + ctx.Data["OpenGraphType"] = "profile" 68 + ctx.Data["OpenGraphImageURL"] = ctx.ContextUser.AvatarLink(ctx) 69 + ctx.Data["OpenGraphURL"] = ctx.ContextUser.HTMLURL() 70 + ctx.Data["OpenGraphDescription"] = ctx.ContextUser.Description 71 + 66 72 // prepare heatmap data 67 73 if setting.Service.EnableUserHeatmap { 68 74 data, err := activities_model.GetUserHeatmapDataByUser(ctx, ctx.ContextUser, ctx.Doer)
+4
services/context/repo.go
··· 634 634 } 635 635 636 636 cardWidth, cardHeight := card.DefaultSize() 637 + ctx.Data["OpenGraphTitle"] = repo.Name 638 + ctx.Data["OpenGraphURL"] = repo.HTMLURL() 639 + ctx.Data["OpenGraphType"] = "object" 640 + ctx.Data["OpenGraphDescription"] = repo.Description 637 641 ctx.Data["OpenGraphImageURL"] = repo.SummaryCardURL() 638 642 ctx.Data["OpenGraphImageWidth"] = cardWidth 639 643 ctx.Data["OpenGraphImageHeight"] = cardHeight
+16 -59
templates/base/head_opengraph.tmpl
··· 1 - {{- /* og:description - a one to two sentence description of your object, maybe it only needs at most 300 bytes */ -}} 1 + {{- /* See https://ogp.me for specification */ -}} 2 2 {{if .OpenGraphTitle}} 3 3 <meta property="og:title" content="{{.OpenGraphTitle}}"> 4 + {{else if .Title}} 5 + <meta property="og:title" content="{{.Title}}"> 6 + {{else}} 7 + <meta property="og:title" content="{{AppDisplayName}}"> 4 8 {{end}} 5 - {{if .OpenGraphDescription}} 6 - <meta property="og:description" content="{{.OpenGraphDescription}}"> 9 + {{- /* og:description - a one to two sentence description of your object, maybe it only needs at most 300 bytes */ -}} 10 + {{if and .OpenGraphDescription (not .OpenGraphNoDescription)}} 11 + <meta property="og:description" content="{{StringUtils.EllipsisString .OpenGraphDescription 300}}"> 7 12 {{end}} 8 13 {{if .OpenGraphURL}} 9 14 <meta property="og:url" content="{{.OpenGraphURL}}"> 15 + {{else}} 16 + <meta property="og:url" content="{{AppUrl}}{{.Link}}"> 17 + {{end}} 18 + {{if .OpenGraphType}} 19 + <meta property="og:type" content="{{.OpenGraphType}}"> 20 + {{else}} 21 + <meta property="og:type" content="website"> 10 22 {{end}} 11 23 {{if .OpenGraphImageURL}} 12 24 <meta property="og:image" content="{{.OpenGraphImageURL}}"> ··· 19 31 {{if .OpenGraphImageAltText}} 20 32 <meta property="og:image:alt" content="{{.OpenGraphImageAltText}}"> 21 33 {{end}} 22 - {{end}} 23 - {{if .PageIsUserProfile}} 24 - <meta property="og:title" content="{{.ContextUser.DisplayName}}"> 25 - <meta property="og:type" content="profile"> 26 - <meta property="og:image" content="{{.ContextUser.AvatarLink ctx}}"> 27 - <meta property="og:url" content="{{.ContextUser.HTMLURL}}"> 28 - {{if .ContextUser.Description}} 29 - <meta property="og:description" content="{{StringUtils.EllipsisString .ContextUser.Description 300}}"> 30 - {{end}} 31 - {{else if .Repository}} 32 - {{if .Issue}} 33 - <meta property="og:title" content="{{.Issue.Title}}"> 34 - <meta property="og:url" content="{{.Issue.HTMLURL}}"> 35 - {{if .Issue.Content}} 36 - <meta property="og:description" content="{{StringUtils.EllipsisString .Issue.Content 300}}"> 37 - {{end}} 38 - {{else if or .PageIsDiff .IsViewFile}} 39 - <meta property="og:title" content="{{.Title}}"> 40 - <meta property="og:url" content="{{AppUrl}}{{.Link}}"> 41 - {{if and .PageIsDiff .Commit}} 42 - {{- $commitMessageParts := StringUtils.Cut .Commit.Message "\n" -}} 43 - {{- $commitMessageBody := index $commitMessageParts 1 -}} 44 - {{- if $commitMessageBody -}} 45 - <meta property="og:description" content="{{StringUtils.EllipsisString $commitMessageBody 300}}"> 46 - {{- end -}} 47 - {{end}} 48 - {{else if .Pages}} 49 - <meta property="og:title" content="{{.Title}}"> 50 - <meta property="og:url" content="{{AppUrl}}{{.Link}}"> 51 - {{if .Repository.Description}} 52 - <meta property="og:description" content="{{StringUtils.EllipsisString .Repository.Description 300}}"> 53 - {{end}} 54 - {{else}} 55 - {{if not .OpenGraphTitle}} 56 - <meta property="og:title" content="{{.Repository.Name}}"> 57 - {{end}} 58 - {{if not .OpenGraphURL}} 59 - <meta property="og:url" content="{{.Repository.HTMLURL}}"> 60 - {{end}} 61 - {{if and (.Repository.Description) (not .OpenGraphDescription)}} 62 - <meta property="og:description" content="{{StringUtils.EllipsisString .Repository.Description 300}}"> 63 - {{end}} 64 - {{end}} 65 - <meta property="og:type" content="object"> 66 - {{if and (not .Issue) (not .OpenGraphImageURL)}} 67 - {{if (.Repository.AvatarLink ctx)}} 68 - <meta property="og:image" content="{{.Repository.AvatarLink ctx}}"> 69 - {{else}} 70 - <meta property="og:image" content="{{.Repository.Owner.AvatarLink ctx}}"> 71 - {{end}} 72 - {{end}} 73 34 {{else}} 74 - <meta property="og:title" content="{{AppDisplayName}}"> 75 - <meta property="og:type" content="website"> 76 - <meta property="og:image" content="{{AssetUrlPrefix}}/img/logo.png"> 77 - <meta property="og:url" content="{{AppUrl}}"> 78 - <meta property="og:description" content="{{MetaDescription}}"> 35 + <meta property="og:image" content="{{AssetUrlPrefix}}/img/logo.png"> 79 36 {{end}} 80 37 <meta property="og:site_name" content="{{AppDisplayName}}">