Documentation
¶
Index ¶
- func LogValidationWarnings(v SchemaValidator)
- type Action
- type AggregateRating
- type Answer
- type Article
- type Brand
- type BreadcrumbList
- type ContactPoint
- type Event
- type FAQPage
- type GeoCoordinates
- type ImageObject
- type ListItem
- type LocalBusiness
- type NavigationLink
- type Offer
- type Organization
- type Person
- type Place
- type PostalAddress
- type Product
- type Question
- type Rating
- type Review
- type SchemaValidator
- type SiteNavigationElement
- type SiteNavigationElementList
- func (itemList *SiteNavigationElementList) FromSitemapFile(filename string) (err error)
- func (itemList *SiteNavigationElementList) ToGoHTMLJsonLd() (template.HTML, error)
- func (snl *SiteNavigationElementList) ToJsonLd() templ.Component
- func (itemList *SiteNavigationElementList) ToSitemapBytes() ([]byte, error)
- func (itemList *SiteNavigationElementList) ToSitemapFile(filename string) error
- func (snl *SiteNavigationElementList) Validate() (bool, []string)
- type StringList
- type Target
- type WebPage
- type WebSite
- type XMLSitemap
- type XMLSitemapUrl
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LogValidationWarnings ¶ added in v0.2.0
func LogValidationWarnings(v SchemaValidator)
Types ¶
type Action ¶
type Action struct {
Type string `json:"@type"`
Target *Target `json:"target"`
QueryInput string `json:"query-input"`
}
Action represents a Schema.org Action object
type AggregateRating ¶
type AggregateRating struct {
Type string `json:"@type"`
RatingValue float64 `json:"ratingValue,omitempty"`
ReviewCount int `json:"reviewCount,omitempty"`
}
AggregateRating represents a Schema.org AggregateRating object
type Article ¶
type Article struct {
Context string `json:"@context"`
Type string `json:"@type"`
Headline string `json:"headline,omitempty"`
Image []string `json:"image,omitempty"`
Author *Person `json:"author,omitempty"`
Publisher *Organization `json:"publisher,omitempty"`
DatePublished string `json:"datePublished,omitempty"`
DateModified string `json:"dateModified,omitempty"`
Description string `json:"description,omitempty"`
}
Article represents a Schema.org Article object. For more details about the meaning of the properties see: https://schema.org/Article
Example usage:
Pure struct usage:
article := &schemaorg.Article{
Headline: "Example Article Headline",
Image: []string{"https://www.example.com/images/article.jpg"},
Author: &schemaorg.Person{Name: "Jane Doe"},
Publisher: &schemaorg.Organization{Name: "Example Publisher"},
DatePublished: "2024-09-15",
DateModified: "2024-09-16",
Description: "This is an example article.",
}
Factory method usage:
article := schemaorg.NewArticle(
"Example Article Headline",
[]string{"https://www.example.com/images/article.jpg"},
&schemaorg.Person{Name: "Jane Doe"},
&schemaorg.Organization{Name: "Example Publisher"},
"2024-09-15",
"2024-09-16",
"This is an example article",
)
// Rendering JSON-LD using templ:
templ Page() {
@article.ToJsonLd()
}
// Rendering JSON-LD as `template.HTML` value:
jsonLdHtml := article.ToGoHTMLJsonLd()
Expected output:
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "Example Article Headline",
"image": ["https://www.example.com/images/article.jpg"],
"author": {"@type": "Person", "name": "Jane Doe"},
"publisher": {"@type": "Organization", "name": "Example Publisher"},
"datePublished": "2024-09-15",
"dateModified": "2024-09-16",
"description": "This is an example article"
}
func NewArticle ¶
func NewArticle(headline string, images []string, author *Person, publisher *Organization, datePublished, dateModified, description string) *Article
NewArticle initializes an Article with default context and type.
func (*Article) ToGoHTMLJsonLd ¶
ToGoHTMLJsonLd renders the Article struct as `template.HTML` value for Go's `html/template`.
type BreadcrumbList ¶
type BreadcrumbList struct {
Context string `json:"@context"`
Type string `json:"@type"`
ItemListElement []ListItem `json:"itemListElement"`
}
BreadcrumbList represents a Schema.org BreadcrumbList object. For more details about the meaning of the properties see:https://schema.org/BreadcrumbList
Example usage:
Pure struct usage:
breadcrumb := &schemaorg.BreadcrumbList{
ItemListElement: []schemaorg.ListItem{
{Name: "Home", Item: "https://www.example.com", Position: 1},
{Name: "About Us", Item: "https://www.example.com/about", Position: 2},
},
}
Factory method usage:
breadcrumb := schemaorg.NewBreadcrumbList(
[]schemaorg.ListItem{
{Name: "Home", Item: "https://www.example.com", Position: 1},
{Name: "About Us", Item: "https://www.example.com/about", Position: 2},
},
)
Example usage with `NewBreadcrumbListFromUrl`:
func HandleAbout(w http.ResponseWriter, r *http.Request) {
pageURL := teseo.GetFullURL(r)
breadcrumbList, err := schemaorg.NewBreadcrumbListFromUrl(pageURL)
if err != nil {
fmt.Println("Error generating breadcrumb list:", err)
return
}
// pass the component to your page and render with `@breadcrumbList.ToJsonLd()`
err = pages.AboutPage(breadcrumbList).Render(r.Context(), w)
if err != nil {
return
}
}
// Rendering JSON-LD using templ:
templ Page() {
@breadcrumb.ToJsonLd()
}
// Rendering JSON-LD as `template.HTML` value:
jsonLdHtml := breadcrumb.ToGoHTMLJsonLd()
Expected output:
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{"@type": "ListItem", "position": 1, "name": "Home", "item": "https://www.example.com"},
{"@type": "ListItem", "position": 2, "name": "About Us", "item": "https://www.example.com/about"}
]
}
func NewBreadcrumbList ¶
func NewBreadcrumbList(listItem []ListItem) *BreadcrumbList
NewBreadcrumbList initializes a BreadcrumbList with default context and type.
func NewBreadcrumbListFromUrl ¶
func NewBreadcrumbListFromUrl(url string) (*BreadcrumbList, error)
NewBreadcrumbListFromUrl initializes an BreadcrumbList from the URL string.
func (*BreadcrumbList) ToGoHTMLJsonLd ¶
func (bcl *BreadcrumbList) ToGoHTMLJsonLd() (template.HTML, error)
ToGoHTMLJsonLd renders the BreadcrumbList struct as `template.HTML` value for Go's `html/template`.
func (*BreadcrumbList) ToJsonLd ¶
func (bcl *BreadcrumbList) ToJsonLd() templ.Component
ToJsonLd converts the BreadcrumbList struct to a JSON-LD `templ.Component`.
func (*BreadcrumbList) Validate ¶ added in v0.2.0
func (bcl *BreadcrumbList) Validate() []string
Validate checks if the BreadcrumbList has the required structure.
type ContactPoint ¶
type ContactPoint struct {
Type string `json:"@type"`
Telephone string `json:"telephone,omitempty"`
ContactType string `json:"contactType,omitempty"`
ContactOption StringList `json:"contactOption,omitempty"`
AreaServed StringList `json:"areaServed,omitempty"`
AvailableLanguage string `json:"availableLanguage,omitempty"`
}
ContactPoint represents a Schema.org ContactPoint object For more details about the meaning of the properties see: https://schema.org/ContactPoint
type Event ¶
type Event struct {
Context string `json:"@context"`
Type string `json:"@type"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
StartDate string `json:"startDate,omitempty"`
EndDate string `json:"endDate,omitempty"`
Location *Place `json:"location,omitempty"`
Organizer *Organization `json:"organizer,omitempty"`
Performer *Person `json:"performer,omitempty"`
Image []string `json:"image,omitempty"`
EventStatus string `json:"eventStatus,omitempty"`
EventAttendanceMode string `json:"eventAttendanceMode,omitempty"`
Offers *Offer `json:"offers,omitempty"`
}
Event represents a Schema.org Event object. For more details about the meaning of the properties see:https://schema.org/Event
Example usage:
Pure struct usage:
event := &schemaorg.Event{
Name: "Example Event",
StartDate: "2024-09-20T19:00:00",
EndDate: "2024-09-20T23:00:00",
Location: &schemaorg.Place{Name: "Example Venue", Address: "123 Main St"},
Description: "This is an example event.",
}
Factory method usage:
event := schemaorg.NewEvent(
"Example Event",
"2024-09-20T19:00:00",
"2024-09-20T23:00:00",
&schemaorg.Place{Name: "Example Venue", Address: "123 Main St"},
"This is an example event",
)
// Rendering JSON-LD using templ:
templ Page() {
@event.ToJsonLd()
}
// Rendering JSON-LD as `template.HTML` value:
jsonLdHtml := event.ToGoHTMLJsonLd()
Expected output:
{
"@context": "https://schema.org",
"@type": "Event",
"name": "Example Event",
"startDate": "2024-09-20T19:00:00",
"endDate": "2024-09-20T23:00:00",
"location": {"@type": "Place", "name": "Example Venue", "address": "123 Main St"},
"description": "This is an example event"
}
func NewEvent ¶
func NewEvent(name, description, startDate, endDate string, location *Place, organizer *Organization, performer *Person, images []string, eventStatus, eventAttendanceMode string, offers *Offer) *Event
NewEvent initializes an Event with default context and type.
func (*Event) ToGoHTMLJsonLd ¶
ToGoHTMLJsonLd renders the Event struct as `template.HTML` value for Go's `html/template`.
type FAQPage ¶
type FAQPage struct {
Context string `json:"@context"`
Type string `json:"@type"`
MainEntity []*Question `json:"mainEntity,omitempty"`
}
FAQPage represents a Schema.org FAQPage object. For more details about the meaning of the properties see:https://schema.org/FAQPage
Example usage:
Pure struct usage:
faqPage := &schemaorg.FAQPage{
MainEntity: []schemaorg.Question{
{Question: "What is Schema.org?", Answer: &schemaorg.Answer{Answer: "Schema.org is a structured data vocabulary."}},
},
}
Factory method usage:
faqPage := schemaorg.NewFAQPage(
[]schemaorg.Question{
{Question: "What is Schema.org?", Answer: &schemaorg.Answer{Answer: "Schema.org is a structured data vocabulary."}},
},
)
// Rendering JSON-LD using templ:
templ Page() {
@faqPage.ToJsonLd()
}
// Rendering JSON-LD as `template.HTML` value:
jsonLdHtml := faqPage.ToGoHTMLJsonLd()
Expected output:
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": "What is Schema.org?",
"acceptedAnswer": {"@type": "Answer", "text": "Schema.org is a structured data vocabulary."}
}
]
}
func NewFAQPage ¶
NewFAQPage initializes an FAQPage with default context and type.
func (*FAQPage) ToGoHTMLJsonLd ¶
ToGoHTMLJsonLd renders the FAQPage struct as`template.HTML` value for Go's `html/template`.
type GeoCoordinates ¶
type GeoCoordinates struct {
Type string `json:"@type"`
Latitude float64 `json:"latitude,omitempty"`
Longitude float64 `json:"longitude,omitempty"`
}
GeoCoordinates represents a Schema.org GeoCoordinates object
type ImageObject ¶
ImageObject represents a Schema.org ImageObject object For more details about the meaning of the properties see: https://schema.org/ImageObject
type ListItem ¶
type ListItem struct {
Type string `json:"@type"`
Position int `json:"position,omitempty"`
Name string `json:"name,omitempty"`
Item string `json:"item,omitempty"`
}
ListItem represents a Schema.org ListItem object For more details about the meaning of the properties see: https://schema.org/ListItem
type LocalBusiness ¶
type LocalBusiness struct {
Context string `json:"@context"`
Type string `json:"@type"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
URL string `json:"url,omitempty"`
Logo *ImageObject `json:"logo,omitempty"`
Telephone string `json:"telephone,omitempty"`
Address *PostalAddress `json:"address,omitempty"`
OpeningHours []string `json:"openingHours,omitempty"`
Geo *GeoCoordinates `json:"geo,omitempty"`
AggregateRating *AggregateRating `json:"aggregateRating,omitempty"`
Review []*Review `json:"review,omitempty"`
}
LocalBusiness represents a Schema.org LocalBusiness object. For more details about the meaning of the properties see:https://schema.org/LocalBusiness
Example usage:
Pure struct usage:
localBusiness := &schemaorg.LocalBusiness{
Name: "Example Business",
Address: &schemaorg.PostalAddress{StreetAddress: "123 Main St", AddressLocality: "Anytown", AddressRegion: "CA", PostalCode: "12345"},
Telephone: "+1-800-555-1234",
Description: "This is an example local business.",
}
Factory method usage:
localBusiness := schemaorg.NewLocalBusiness(
"Example Business",
&schemaorg.PostalAddress{StreetAddress: "123 Main St", AddressLocality: "Anytown", AddressRegion: "CA", PostalCode: "12345"},
"+1-800-555-1234",
"This is an example local business",
)
// Rendering JSON-LD using templ:
templ Page() {
@localBusiness.ToJsonLd()
}
// Rendering JSON-LD as `template.HTML` value:
jsonLdHtml := localBusiness.ToGoHTMLJsonLd()
Expected output:
{
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "Example Business",
"address": {
"@type": "PostalAddress",
"streetAddress": "123 Main St",
"addressLocality": "Anytown",
"addressRegion": "CA",
"postalCode": "12345"
},
"telephone": "+1-800-555-1234",
"description": "This is an example local business"
}
func NewLocalBusiness ¶
func NewLocalBusiness(name string, description string, url string, telephone string, logo *ImageObject, address *PostalAddress, openingHours []string, geo *GeoCoordinates, aggregateRating *AggregateRating, reviews []*Review) *LocalBusiness
NewLocalBusiness initializes a LocalBusiness with default context and type.
func (*LocalBusiness) ToGoHTMLJsonLd ¶
func (lb *LocalBusiness) ToGoHTMLJsonLd() (template.HTML, error)
ToGoHTMLJsonLd renders the LocalBusiness struct as `template.HTML` value for Go's `html/template`.
func (*LocalBusiness) ToJsonLd ¶
func (lb *LocalBusiness) ToJsonLd() templ.Component
ToJsonLd converts the LocalBusiness struct to a JSON-LD `templ.Component`.
func (*LocalBusiness) Validate ¶ added in v0.2.0
func (lb *LocalBusiness) Validate() []string
Validate returns a list of recommended validation warnings for schema.org LocalBusiness.
type NavigationLink ¶ added in v0.2.1
type NavigationLink struct {
}
NavigationLink represents a structured navigation item with optional description.
type Offer ¶
type Offer struct {
Type string `json:"@type"`
URL string `json:"url,omitempty"`
PriceCurrency string `json:"priceCurrency,omitempty"`
Price string `json:"price,omitempty"`
Availability string `json:"availability,omitempty"`
ItemCondition string `json:"itemCondition,omitempty"`
}
Offer represents a Schema.org Offer object
type Organization ¶
type Organization struct {
Context string `json:"@context"`
Type string `json:"@type"`
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
Logo *ImageObject `json:"logo,omitempty"`
ContactPoints []ContactPoint `json:"contactPoint,omitempty"`
SameAs []string `json:"sameAs,omitempty"`
}
Organization represents a Schema.org Organization object For more details about the meaning of the properties see: https://schema.org/Organization
func NewOrganization ¶
func NewOrganization(name string, url string, logoURL string, contactPoints []ContactPoint, sameAs []string) *Organization
NewOrganization initializes an Organization with default context and type.
func (*Organization) ToGoHTMLJsonLd ¶
func (org *Organization) ToGoHTMLJsonLd() (template.HTML, error)
ToGoHTMLJsonLd renders the Organization struct as `template.HTML` value for Go's `html/template`.
func (*Organization) ToJsonLd ¶
func (org *Organization) ToJsonLd() templ.Component
ToJsonLd converts the Organization struct to a JSON-LD `templ.Component`.
func (*Organization) Validate ¶ added in v0.2.0
func (org *Organization) Validate() []string
Validate checks for recommended fields in Organization.
type Person ¶
type Person struct {
Context string `json:"@context"`
Type string `json:"@type"`
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
Email string `json:"email,omitempty"`
Image *ImageObject `json:"image,omitempty"`
JobTitle string `json:"jobTitle,omitempty"`
WorksFor *Organization `json:"worksFor,omitempty"`
SameAs []string `json:"sameAs,omitempty"`
Gender string `json:"gender,omitempty"`
BirthDate string `json:"birthDate,omitempty"`
Nationality string `json:"nationality,omitempty"`
Telephone string `json:"telephone,omitempty"`
Address *PostalAddress `json:"address,omitempty"`
Affiliation *Organization `json:"affiliation,omitempty"`
}
Person represents a Schema.org Person object For more details about the meaning of the properties see: https://schema.org/Person
func NewPerson ¶
func NewPerson(name string, url string, email string, image *ImageObject, jobTitle string, worksFor *Organization, sameAs []string, gender string, birthDate string, nationality string, telephone string, address *PostalAddress, affiliation *Organization) *Person
NewPerson initializes a Person with default context and type.
func (*Person) ToGoHTMLJsonLd ¶
ToGoHTMLJsonLd renders the Person struct as `template.HTML` value for Go's `html/template`.
type Place ¶
type Place struct {
Context string `json:"@context"`
Type string `json:"@type"`
Name string `json:"name,omitempty"`
Address *PostalAddress `json:"address,omitempty"`
Geo *GeoCoordinates `json:"geo,omitempty"`
}
Place represents a Schema.org Place object
type PostalAddress ¶
type PostalAddress struct {
Type string `json:"@type"`
StreetAddress string `json:"streetAddress,omitempty"`
AddressLocality string `json:"addressLocality,omitempty"`
AddressRegion string `json:"addressRegion,omitempty"`
PostalCode string `json:"postalCode,omitempty"`
AddressCountry string `json:"addressCountry,omitempty"`
}
PostalAddress represents a Schema.org PostalAddress object
type Product ¶
type Product struct {
Context string `json:"@context"`
Type string `json:"@type"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Image []string `json:"image,omitempty"`
SKU string `json:"sku,omitempty"`
Brand *Brand `json:"brand,omitempty"`
Offers *Offer `json:"offers,omitempty"`
Category string `json:"category,omitempty"`
AggregateRating *AggregateRating `json:"aggregateRating,omitempty"`
Review []*Review `json:"review,omitempty"`
}
Product represents a Schema.org Product object. For more details about the meaning of the properties see: https://schema.org/Product
Example usage:
Pure struct usage:
product := &schemaorg.Product{
Name: "Example Product",
Description: "This is an example product description.",
SKU: "12345",
Brand: &schemaorg.Brand{Name: "Example Brand"},
Offers: &schemaorg.Offer{Price: "29.99", PriceCurrency: "USD"},
}
Factory method usage:
product := schemaorg.NewProduct(
"Example Product",
"This is an example product description.",
"12345",
&schemaorg.Brand{Name: "Example Brand"},
&schemaorg.Offer{Price: "29.99", PriceCurrency: "USD"},
)
// Rendering JSON-LD using templ:
templ Page() {
@product.ToJsonLd()
}
// Rendering JSON-LD as `template.HTML` value:
jsonLdHtml := product.ToGoHTMLJsonLd()
Expected output:
{
"@context": "https://schema.org",
"@type": "Product",
"name": "Example Product",
"description": "This is an example product description",
"sku": "12345",
"brand": {"@type": "Brand", "name": "Example Brand"},
"offers": {
"@type": "Offer",
"price": "29.99",
"priceCurrency": "USD"
}
}
func NewProduct ¶
func NewProduct(name, description string, image []string, sku string, brand *Brand, offers *Offer, category string, aggregateRating *AggregateRating, reviews []*Review) *Product
NewProduct initializes a Product with default context and type.
func (*Product) ToGoHTMLJsonLd ¶
ToGoHTMLJsonLd renders the Product struct as `template.HTML` value for Go's `html/template`.
type Question ¶
type Question struct {
Type string `json:"@type"`
Name string `json:"name,omitempty"`
AcceptedAnswer *Answer `json:"acceptedAnswer,omitempty"`
}
Question represents a Schema.org Question object
func NewQuestion ¶
NewQuestion initializes a Question with default type.
type Rating ¶
type Rating struct {
Type string `json:"@type"`
RatingValue float64 `json:"ratingValue,omitempty"`
BestRating float64 `json:"bestRating,omitempty"`
}
Rating represents a Schema.org Rating object
type Review ¶
type Review struct {
Type string `json:"@type"`
Author *Person `json:"author,omitempty"`
DatePublished string `json:"datePublished,omitempty"`
ReviewBody string `json:"reviewBody,omitempty"`
ReviewRating *Rating `json:"reviewRating,omitempty"`
}
Review represents a Schema.org Review object
type SchemaValidator ¶ added in v0.2.0
type SchemaValidator interface {
// Validate returns a slice of warning messages for missing recommended or required fields.
Validate() []string
}
SchemaValidator defines an interface for types that can be validated for schema.org compliance.
type SiteNavigationElement ¶
type SiteNavigationElement struct {
}
SiteNavigationElement represents a Schema.org SiteNavigationElement.
func NewSimpleSiteNavigationElement ¶ added in v0.2.1
func NewSimpleSiteNavigationElement(position int, name, url string) SiteNavigationElement
NewSimpleSiteNavigationElement creates a SiteNavigationElement with no description.
func NewSiteNavigationElement ¶
func NewSiteNavigationElement(position int, name, description, url string) SiteNavigationElement
NewSiteNavigationElement creates a SiteNavigationElement with full control over all fields.
func NewSiteNavigationElementsFromLinks ¶ added in v0.2.1
func NewSiteNavigationElementsFromLinks(links []NavigationLink) []SiteNavigationElement
NewSiteNavigationElementsFromLinks creates SiteNavigationElement items from a slice of NavigationLink structs. The position is assigned incrementally starting at 1.
type SiteNavigationElementList ¶ added in v0.2.1
type SiteNavigationElementList struct {
}
SiteNavigationElementList represents an ItemList of SiteNavigationElement.
func NewSiteNavigationElementList ¶ added in v0.2.1
func NewSiteNavigationElementList( identifier string, items []SiteNavigationElement, ) *SiteNavigationElementList
NewSiteNavigationElementList creates a SiteNavigationElementList (ItemList) with default context/type and an optional identifier.
func (*SiteNavigationElementList) FromSitemapFile ¶ added in v0.2.1
func (itemList *SiteNavigationElementList) FromSitemapFile(filename string) (err error)
FromSitemapFile parses a sitemap XML file and populates the SiteNavigationElement struct.
func (*SiteNavigationElementList) ToGoHTMLJsonLd ¶ added in v0.2.1
func (itemList *SiteNavigationElementList) ToGoHTMLJsonLd() (template.HTML, error)
ToGoHTMLJsonLd renders the SiteNavigationElement struct as `template.HTML` value for Go's `html/template`.
func (*SiteNavigationElementList) ToJsonLd ¶ added in v0.2.1
func (snl *SiteNavigationElementList) ToJsonLd() templ.Component
ToJsonLd converts the SiteNavigationElement struct to a JSON-LD `templ.Component`.
func (*SiteNavigationElementList) ToSitemapBytes ¶ added in v0.2.1
func (itemList *SiteNavigationElementList) ToSitemapBytes() ([]byte, error)
ToSitemapBytes returns the XML sitemap content as a byte slice.
func (*SiteNavigationElementList) ToSitemapFile ¶ added in v0.2.1
func (itemList *SiteNavigationElementList) ToSitemapFile(filename string) error
ToSitemapFile generates a sitemap XML file and writes it to the specified path.
func (*SiteNavigationElementList) Validate ¶ added in v0.2.1
func (snl *SiteNavigationElementList) Validate() (bool, []string)
type StringList ¶ added in v0.2.3
type StringList []string
StringList supports both a single string or a slice of strings in JSON, and always trims input strings.
func (StringList) IsZero ¶ added in v0.2.3
func (s StringList) IsZero() bool
IsZero reports whether the value is empty or contains only one empty string.
func (StringList) MarshalJSON ¶ added in v0.2.3
func (s StringList) MarshalJSON() ([]byte, error)
MarshalJSON encodes the value as either a string or an array of strings.
func (StringList) String ¶ added in v0.2.3
func (s StringList) String() string
String returns a comma-separated string representation.
func (StringList) ToSlice ¶ added in v0.2.3
func (s StringList) ToSlice() []string
ToSlice returns a canonical []string value or nil if empty.
func (*StringList) UnmarshalJSON ¶ added in v0.2.3
func (s *StringList) UnmarshalJSON(data []byte) error
UnmarshalJSON accepts both string and []string, and trims all values.
type WebPage ¶
type WebPage struct {
Context string `json:"@context"`
Type string `json:"@type"`
URL string `json:"url,omitempty"`
Name string `json:"name,omitempty"`
Headline string `json:"headline,omitempty"`
Description string `json:"description,omitempty"`
About string `json:"about,omitempty"`
Keywords string `json:"keywords,omitempty"`
InLanguage string `json:"inLanguage,omitempty"`
IsPartOf string `json:"isPartOf,omitempty"`
LastReviewed string `json:"lastReviewed,omitempty"`
PrimaryImage string `json:"primaryImageOfPage,omitempty"`
DatePublished string `json:"datePublished,omitempty"`
DateModified string `json:"dateModified,omitempty"`
}
WebPage represents a Schema.org WebPage object. For more details about the meaning of the properties see: https://schema.org/WebPage
Example usage:
Pure struct usage:
webpage := &schemaorg.WebPage{
URL: "https://www.example.com",
Name: "Example WebPage",
Headline: "Welcome to Example WebPage",
Description: "This is an example webpage.",
About: "Something related to the home page",
Keywords: "example, webpage, demo",
InLanguage: "en",
}
Factory method usage:
webpage := schemaorg.NewWebPage( "https://www.example.com", "Example WebPage", "Welcome to Example WebPage", "This is an example webpage", "Something related to the home page", "example, webpage, demo", "en", "", "", "", "", "",
)
// Rendering JSON-LD using templ:
templ Page() {
@webPage.ToJsonLd()
}
// Rendering JSON-LD as `template.HTML` value:
jsonLdHtml := webPage.ToGoHTMLJsonLd()
Expected output:
{
"@context": "https://schema.org",
"@type": "WebPage",
"url": "https://www.example.com",
"name": "Example WebPage",
"headline": "Welcome to Example WebPage",
"description": "This is an example webpage",
"keywords": "example, webpage, demo"
}
func NewWebPage ¶
func (*WebPage) ToGoHTMLJsonLd ¶
ToGoHTMLJsonLd renders the WebSite struct as `template.HTML` value for Go's `html/template`.
type WebSite ¶
type WebSite struct {
Context string `json:"@context"`
Type string `json:"@type"`
URL string `json:"url,omitempty"`
Name string `json:"name,omitempty"`
AlternateName string `json:"alternateName,omitempty"`
Description string `json:"description,omitempty"`
PotentialAction *Action `json:"potentialAction,omitempty"`
}
WebSite represents a Schema.org WebSite object
func NewWebSite ¶
func (*WebSite) ToGoHTMLJsonLd ¶
ToGoHTMLJsonLd renders the WebSite struct as `template.HTML` value for Go's `html/template`.
type XMLSitemap ¶
type XMLSitemap struct {
XMLName xml.Name `xml:"urlset"`
Xmlns string `xml:"xmlns,attr"`
Urls []XMLSitemapUrl `xml:"url"`
}
XMLSitemap represents the structure of a sitemap XML file.
type XMLSitemapUrl ¶
XMLSitemapUrl represents a single URL entry in the sitemap XML.