mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-08-29 12:17:00 +00:00
156 lines
5.2 KiB
Go
156 lines
5.2 KiB
Go
package handlers
|
|
|
|
// JSON-LD structured data types for rich results in search engines.
|
|
// These are marshaled to JSON and embedded in <script type="application/ld+json"> tags.
|
|
|
|
// JSONLDOrganization represents a schema.org Organization.
|
|
type JSONLDOrganization struct {
|
|
Context string `json:"@context"`
|
|
Type string `json:"@type"`
|
|
Name string `json:"name"`
|
|
AlternateName string `json:"alternateName,omitempty"`
|
|
URL string `json:"url"`
|
|
Logo string `json:"logo,omitempty"`
|
|
Description string `json:"description,omitempty"`
|
|
SameAs []string `json:"sameAs,omitempty"`
|
|
}
|
|
|
|
// JSONLDWebSite represents a schema.org WebSite with search action.
|
|
type JSONLDWebSite struct {
|
|
Context string `json:"@context"`
|
|
Type string `json:"@type"`
|
|
Name string `json:"name"`
|
|
URL string `json:"url"`
|
|
PotentialAction *JSONLDSearchAction `json:"potentialAction,omitempty"`
|
|
}
|
|
|
|
// JSONLDSearchAction represents a schema.org SearchAction.
|
|
type JSONLDSearchAction struct {
|
|
Type string `json:"@type"`
|
|
Target *JSONLDEntryPoint `json:"target"`
|
|
QueryInput string `json:"query-input"`
|
|
}
|
|
|
|
// JSONLDEntryPoint represents a schema.org EntryPoint for search.
|
|
type JSONLDEntryPoint struct {
|
|
Type string `json:"@type"`
|
|
URLTemplate string `json:"urlTemplate"`
|
|
}
|
|
|
|
// JSONLDSoftwareSourceCode represents a schema.org SoftwareSourceCode (for repositories).
|
|
type JSONLDSoftwareSourceCode struct {
|
|
Context string `json:"@context"`
|
|
Type string `json:"@type"`
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
CodeRepository string `json:"codeRepository"`
|
|
Author *JSONLDPerson `json:"author,omitempty"`
|
|
Publisher *JSONLDOrg `json:"publisher,omitempty"`
|
|
License string `json:"license,omitempty"`
|
|
IsBasedOn string `json:"isBasedOn,omitempty"`
|
|
}
|
|
|
|
// JSONLDProfilePage represents a schema.org ProfilePage.
|
|
type JSONLDProfilePage struct {
|
|
Context string `json:"@context"`
|
|
Type string `json:"@type"`
|
|
MainEntity *JSONLDPerson `json:"mainEntity"`
|
|
}
|
|
|
|
// JSONLDPerson represents a schema.org Person.
|
|
type JSONLDPerson struct {
|
|
Type string `json:"@type"`
|
|
Name string `json:"name"`
|
|
URL string `json:"url,omitempty"`
|
|
Image string `json:"image,omitempty"`
|
|
}
|
|
|
|
// JSONLDOrg represents a schema.org Organization (minimal version for embedding).
|
|
type JSONLDOrg struct {
|
|
Type string `json:"@type"`
|
|
Name string `json:"name"`
|
|
URL string `json:"url,omitempty"`
|
|
}
|
|
|
|
// Helper constructors for common JSON-LD objects
|
|
|
|
// NewJSONLDOrganization creates an Organization object for the registry.
|
|
// shortName is the brand name (e.g., "ATCR"), fullName is the full name (e.g., "AT Container Registry").
|
|
func NewJSONLDOrganization(registryURL, shortName, fullName string) JSONLDOrganization {
|
|
return JSONLDOrganization{
|
|
Context: "https://schema.org",
|
|
Type: "Organization",
|
|
Name: shortName,
|
|
AlternateName: fullName,
|
|
URL: "https://" + registryURL,
|
|
Logo: "https://" + registryURL + "/favicon.svg",
|
|
Description: "Decentralized container registry using AT Protocol. Push and pull Docker images with your AT Protocol identity.",
|
|
SameAs: []string{},
|
|
}
|
|
}
|
|
|
|
// NewJSONLDWebSite creates a WebSite object with search action.
|
|
// shortName is the brand name (e.g., "ATCR").
|
|
func NewJSONLDWebSite(registryURL, shortName string) JSONLDWebSite {
|
|
return JSONLDWebSite{
|
|
Context: "https://schema.org",
|
|
Type: "WebSite",
|
|
Name: shortName,
|
|
URL: "https://" + registryURL,
|
|
PotentialAction: &JSONLDSearchAction{
|
|
Type: "SearchAction",
|
|
Target: &JSONLDEntryPoint{
|
|
Type: "EntryPoint",
|
|
URLTemplate: "https://" + registryURL + "/search?q={search_term_string}",
|
|
},
|
|
QueryInput: "required name=search_term_string",
|
|
},
|
|
}
|
|
}
|
|
|
|
// NewJSONLDSoftwareSourceCode creates a SoftwareSourceCode object for a repository.
|
|
// shortName is the brand name (e.g., "ATCR").
|
|
func NewJSONLDSoftwareSourceCode(registryURL, handle, repoName, description, license, sourceURL, shortName string) JSONLDSoftwareSourceCode {
|
|
code := JSONLDSoftwareSourceCode{
|
|
Context: "https://schema.org",
|
|
Type: "SoftwareSourceCode",
|
|
Name: handle + "/" + repoName,
|
|
Description: description,
|
|
CodeRepository: "https://" + registryURL + "/r/" + handle + "/" + repoName,
|
|
Author: &JSONLDPerson{
|
|
Type: "Person",
|
|
Name: handle,
|
|
URL: "https://" + registryURL + "/u/" + handle,
|
|
},
|
|
Publisher: &JSONLDOrg{
|
|
Type: "Organization",
|
|
Name: shortName,
|
|
URL: "https://" + registryURL,
|
|
},
|
|
}
|
|
if license != "" {
|
|
code.License = license
|
|
}
|
|
if sourceURL != "" {
|
|
code.IsBasedOn = sourceURL
|
|
}
|
|
return code
|
|
}
|
|
|
|
// NewJSONLDProfilePage creates a ProfilePage object for a user.
|
|
func NewJSONLDProfilePage(registryURL, handle, avatar string) JSONLDProfilePage {
|
|
person := &JSONLDPerson{
|
|
Type: "Person",
|
|
Name: handle,
|
|
URL: "https://" + registryURL + "/u/" + handle,
|
|
}
|
|
if avatar != "" {
|
|
person.Image = avatar
|
|
}
|
|
return JSONLDProfilePage{
|
|
Context: "https://schema.org",
|
|
Type: "ProfilePage",
|
|
MainEntity: person,
|
|
}
|
|
}
|