schemaorg

package
v0.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 13 Imported by: 4

Documentation

Index

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 Answer

type Answer struct {
	Type string `json:"@type"`
	Text string `json:"text,omitempty"`
}

Answer represents a Schema.org Answer object

func NewAnswer

func NewAnswer(text string) *Answer

NewAnswer initializes an Answer with default type.

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

func (art *Article) ToGoHTMLJsonLd() (template.HTML, error)

ToGoHTMLJsonLd renders the Article struct as `template.HTML` value for Go's `html/template`.

func (*Article) ToJsonLd

func (art *Article) ToJsonLd() templ.Component

ToJsonLd converts the Article struct to a JSON-LD `templ.Component`.

func (*Article) Validate added in v0.2.0

func (art *Article) Validate() []string

Validate checks if the Article has the recommended fields for SEO. It returns a slice of warning messages for missing recommended fields.

type Brand

type Brand struct {
	Type string `json:"@type"`
	Name string `json:"name,omitempty"`
}

Brand represents a Schema.org Brand object

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 (bcl *BreadcrumbList) ToGoHTMLJsonLd() (template.HTML, error)

ToGoHTMLJsonLd renders the BreadcrumbList struct as `template.HTML` value for Go's `html/template`.

func (bcl *BreadcrumbList) ToJsonLd() templ.Component

ToJsonLd converts the BreadcrumbList struct to a JSON-LD `templ.Component`.

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

func (e *Event) ToGoHTMLJsonLd() (template.HTML, error)

ToGoHTMLJsonLd renders the Event struct as `template.HTML` value for Go's `html/template`.

func (*Event) ToJsonLd

func (e *Event) ToJsonLd() templ.Component

ToJsonLd converts the Event struct to a JSON-LD `templ.Component`.

func (*Event) Validate added in v0.2.0

func (e *Event) Validate() []string

Validate returns warnings for missing recommended Event fields.

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

func NewFAQPage(questions []*Question) *FAQPage

NewFAQPage initializes an FAQPage with default context and type.

func (*FAQPage) ToGoHTMLJsonLd

func (fp *FAQPage) ToGoHTMLJsonLd() (template.HTML, error)

ToGoHTMLJsonLd renders the FAQPage struct as`template.HTML` value for Go's `html/template`.

func (*FAQPage) ToJsonLd

func (fp *FAQPage) ToJsonLd() templ.Component

ToJsonLd converts the FAQPage struct to a JSON-LD `templ.Component`.

func (*FAQPage) Validate added in v0.2.0

func (fp *FAQPage) Validate() []string

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

type ImageObject struct {
	Type string `json:"@type"`
	URL  string `json:"url,omitempty"`
}

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"`
	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 struct {
	Name        string
	URL         string
	Description string
}

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"`
	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

func (p *Person) ToGoHTMLJsonLd() (template.HTML, error)

ToGoHTMLJsonLd renders the Person struct as `template.HTML` value for Go's `html/template`.

func (*Person) ToJsonLd

func (p *Person) ToJsonLd() templ.Component

ToJsonLd converts the Person struct to a JSON-LD `templ.Component`.

func (*Person) Validate added in v0.2.0

func (p *Person) Validate() []string

Validate checks for recommended or required fields in Person.

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

func (p *Product) ToGoHTMLJsonLd() (template.HTML, error)

ToGoHTMLJsonLd renders the Product struct as `template.HTML` value for Go's `html/template`.

func (*Product) ToJsonLd

func (p *Product) ToJsonLd() templ.Component

ToJsonLd converts the Product struct to a JSON-LD `templ.Component`.

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

func NewQuestion(name string, answer *Answer) *Question

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 struct {
	Type        string `json:"@type"`
	Position    int    `json:"position,omitempty"`
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	URL         string `json:"url,omitempty"`
}

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(links []NavigationLink) []SiteNavigationElement

NewSiteNavigationElementsFromLinks creates SiteNavigationElement items from a slice of NavigationLink structs. The position is assigned incrementally starting at 1.

type SiteNavigationElementList struct {
	Context         string                  `json:"@context"`
	Type            string                  `json:"@type"`
	Identifier      string                  `json:"identifier,omitempty"`
	ItemListElement []SiteNavigationElement `json:"itemListElement,omitempty"`
}

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 (itemList *SiteNavigationElementList) FromSitemapFile(filename string) (err error)

FromSitemapFile parses a sitemap XML file and populates the SiteNavigationElement struct.

func (itemList *SiteNavigationElementList) ToGoHTMLJsonLd() (template.HTML, error)

ToGoHTMLJsonLd renders the SiteNavigationElement struct as `template.HTML` value for Go's `html/template`.

func (snl *SiteNavigationElementList) ToJsonLd() templ.Component

ToJsonLd converts the SiteNavigationElement struct to a JSON-LD `templ.Component`.

func (itemList *SiteNavigationElementList) ToSitemapBytes() ([]byte, error)

ToSitemapBytes returns the XML sitemap content as a byte slice.

func (itemList *SiteNavigationElementList) ToSitemapFile(filename string) error

ToSitemapFile generates a sitemap XML file and writes it to the specified path.

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 Target

type Target struct {
	Type        string `json:"@type"`
	URLTemplate string `json:"urlTemplate"`
}

Target represents the target of an action in Schema.org

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 NewWebPage(url string, name string, headline string, description string, about string, keywords string, inLanguage string, isPartOf string, lastReviewed string, primaryImage string, datePublished string, dateModified string) *WebPage

func (*WebPage) ToGoHTMLJsonLd

func (wp *WebPage) ToGoHTMLJsonLd() (template.HTML, error)

ToGoHTMLJsonLd renders the WebSite struct as `template.HTML` value for Go's `html/template`.

func (*WebPage) ToJsonLd

func (wp *WebPage) ToJsonLd() templ.Component

ToJsonLd converts the WebPage struct to a JSON-LD `templ.Component`.

func (*WebPage) Validate added in v0.2.0

func (wp *WebPage) Validate() []string

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 NewWebSite(url string, name string, alternateName string, description string, potentialAction *Action) *WebSite

func (*WebSite) ToGoHTMLJsonLd

func (ws *WebSite) ToGoHTMLJsonLd() (template.HTML, error)

ToGoHTMLJsonLd renders the WebSite struct as `template.HTML` value for Go's `html/template`.

func (*WebSite) ToJsonLd

func (ws *WebSite) ToJsonLd() templ.Component

ToJsonLd converts the WebSite struct to a JSON-LD `templ.Component`.

func (*WebSite) Validate added in v0.2.0

func (ws *WebSite) Validate() []string

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

type XMLSitemapUrl struct {
	Loc      string `xml:"loc"`
	Priority string `xml:"priority,omitempty"`
}

XMLSitemapUrl represents a single URL entry in the sitemap XML.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL