fix open graph

This commit is contained in:
Evan Jarrett
2025-12-18 11:27:18 -06:00
parent 044d408cf8
commit afbc039751
4 changed files with 49 additions and 41 deletions
+16 -3
View File
@@ -13,14 +13,27 @@ type PageData struct {
User *db.User // Logged-in user (nil if not logged in)
Query string // Search query from URL parameter
RegistryURL string // Base registry URL
// Open Graph meta tag fields - set by individual page handlers
OGTitle string // og:title content
OGDescription string // og:description content
OGImage string // og:image URL
OGType string // og:type (website, profile, etc.)
OGURL string // og:url - canonical URL for the page
}
// NewPageData creates a PageData struct with common fields populated from the request
// Sets default OG values for the home page - individual handlers override these
func NewPageData(r *http.Request, registryURL string) PageData {
return PageData{
User: middleware.GetUser(r),
Query: r.URL.Query().Get("q"),
RegistryURL: registryURL,
User: middleware.GetUser(r),
Query: r.URL.Query().Get("q"),
RegistryURL: registryURL,
OGTitle: "ATCR - Distributed Container Registry",
OGDescription: "Push and pull Docker images on the AT Protocol",
OGImage: registryURL + "/web-app-manifest-512x512.png",
OGType: "website",
OGURL: registryURL,
}
}
+17 -1
View File
@@ -206,6 +206,22 @@ func (h *RepositoryPageHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
}
}
// Build page data with OG tags for repository
pageData := NewPageData(r, h.RegistryURL)
pageData.OGTitle = owner.Handle + "/" + repository + " - ATCR"
pageData.OGType = "website"
pageData.OGURL = h.RegistryURL + "/r/" + owner.Handle + "/" + repository
if repo.Description != "" {
pageData.OGDescription = repo.Description
} else {
pageData.OGDescription = "Container image on ATCR"
}
if repo.IconURL != "" {
pageData.OGImage = repo.IconURL
} else if owner.Avatar != "" {
pageData.OGImage = owner.Avatar
}
data := struct {
PageData
Owner *db.User // Repository owner
@@ -217,7 +233,7 @@ func (h *RepositoryPageHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
IsOwner bool // Whether current user owns this repository
ReadmeHTML template.HTML
}{
PageData: NewPageData(r, h.RegistryURL),
PageData: pageData,
Owner: owner,
Repository: repo,
Tags: tagsWithPlatforms,
+11 -1
View File
@@ -79,13 +79,23 @@ func (h *UserPageHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
})
}
// Build page data with OG tags for user profile
pageData := NewPageData(r, h.RegistryURL)
pageData.OGTitle = viewedUser.Handle + " - ATCR"
pageData.OGDescription = "Container images by " + viewedUser.Handle + " on ATCR"
pageData.OGType = "profile"
pageData.OGURL = h.RegistryURL + "/u/" + viewedUser.Handle
if viewedUser.Avatar != "" {
pageData.OGImage = viewedUser.Avatar
}
data := struct {
PageData
ViewedUser *db.User // User whose page we're viewing
Repositories []db.RepoCardData
HasProfile bool
}{
PageData: NewPageData(r, h.RegistryURL),
PageData: pageData,
ViewedUser: viewedUser,
Repositories: cards,
HasProfile: hasProfile,
+5 -36
View File
@@ -3,42 +3,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Open Graph Meta Tags -->
{{ if .ViewedUser }}
<!-- User Profile Page -->
<meta property="og:title" content="{{ .ViewedUser.Handle }} - ATCR">
<meta property="og:description" content="Container images by {{ .ViewedUser.Handle }} on ATCR">
{{ if .ViewedUser.Avatar }}
<meta property="og:image" content="{{ .ViewedUser.Avatar }}">
{{ else }}
<meta property="og:image" content="{{ .RegistryURL }}/web-app-manifest-512x512.png">
{{ end }}
<meta property="og:type" content="profile">
<meta property="og:url" content="{{ .RegistryURL }}/u/{{ .ViewedUser.Handle }}">
{{ else if .Repository }}
<!-- Repository Page -->
<meta property="og:title" content="{{ .Owner.Handle }}/{{ .Repository.Name }} - ATCR">
{{ if .Repository.Description }}
<meta property="og:description" content="{{ .Repository.Description }}">
{{ else }}
<meta property="og:description" content="Container image on ATCR">
{{ end }}
{{ if .Repository.IconURL }}
<meta property="og:image" content="{{ .Repository.IconURL }}">
{{ else if .Owner.Avatar }}
<meta property="og:image" content="{{ .Owner.Avatar }}">
{{ else }}
<meta property="og:image" content="{{ .RegistryURL }}/web-app-manifest-512x512.png">
{{ end }}
<meta property="og:type" content="website">
<meta property="og:url" content="{{ .RegistryURL }}/r/{{ .Owner.Handle }}/{{ .Repository.Name }}">
{{ else }}
<!-- Home Page / Default -->
<meta property="og:title" content="ATCR - Distributed Container Registry">
<meta property="og:description" content="Push and pull Docker images on the AT Protocol">
<meta property="og:image" content="{{ .RegistryURL }}/web-app-manifest-512x512.png">
<meta property="og:type" content="website">
<meta property="og:url" content="{{ .RegistryURL }}">
{{ end }}
<meta property="og:title" content="{{ .OGTitle }}">
<meta property="og:description" content="{{ .OGDescription }}">
<meta property="og:image" content="{{ .OGImage }}">
<meta property="og:type" content="{{ .OGType }}">
<meta property="og:url" content="{{ .OGURL }}">
<meta property="og:site_name" content="ATCR">
<!-- Favicons -->