Files
at-container-registry/pkg/appview/handlers/meta.go
T

62 lines
1.8 KiB
Go

package handlers
// PageMeta holds all metadata for a page's <head> section.
// Use the builder methods to construct it with a fluent API.
type PageMeta struct {
Title string // Page title (required)
Description string // Meta description (required)
Canonical string // Canonical URL (optional)
Robots string // Robots directive, e.g. "noindex" (optional, defaults to "index, follow")
OGType string // OpenGraph type, defaults to "website"
OGImage string // OpenGraph image URL (optional)
TwitterCard string // Twitter card type, defaults to "summary_large_image"
SiteName string // Site name for og:site_name (optional, defaults to "ATCR")
JSONLD []any // JSON-LD structured data objects (optional)
}
// NewPageMeta creates a new PageMeta with required fields and sensible defaults.
func NewPageMeta(title, description string) *PageMeta {
return &PageMeta{
Title: title,
Description: description,
OGType: "website",
TwitterCard: "summary_large_image",
}
}
// WithCanonical sets the canonical URL.
func (m *PageMeta) WithCanonical(url string) *PageMeta {
m.Canonical = url
return m
}
// WithOGImage sets the OpenGraph image URL.
func (m *PageMeta) WithOGImage(url string) *PageMeta {
m.OGImage = url
return m
}
// WithOGType sets the OpenGraph type (e.g., "website", "profile", "article").
func (m *PageMeta) WithOGType(ogType string) *PageMeta {
m.OGType = ogType
return m
}
// WithRobots sets the robots meta directive (e.g., "noindex").
func (m *PageMeta) WithRobots(robots string) *PageMeta {
m.Robots = robots
return m
}
// WithJSONLD sets the JSON-LD structured data objects.
func (m *PageMeta) WithJSONLD(data ...any) *PageMeta {
m.JSONLD = data
return m
}
// WithSiteName sets the site name for og:site_name.
func (m *PageMeta) WithSiteName(name string) *PageMeta {
m.SiteName = name
return m
}