Documentation
¶
Overview ¶
Package seo provides typed Schema.org structs that marshal to the JSON-LD shape Google and other crawlers consume for rich results (FAQ snippets, product cards, breadcrumb trails, article cards).
Each type carries the @context + @type envelope automatically; the caller fills in the descriptive fields and hands the value to Render (or to a screen's HeadHTML implementation), which produces a `<script type="application/ld+json">` block. The script element is data, not code — strict CSP (`default-src 'self'`) permits it alongside `<script type="application/json">`.
Common usage from a screen:
func (s *ProductScreen) HeadHTML() string {
return string(seo.Render(seo.Product{
Name: s.product.Name,
Description: s.product.Description,
Image: s.product.HeroURL,
}))
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Render ¶
Render emits one <script type="application/ld+json"> tag per item. JSON is marshaled with html.UnescapeString-safe content — the only dangerous sequence inside a `<script>` body is `</`, which we neutralize by escaping the `<`.
The opening and closing <script> tags are split across two distinct Go string literals on purpose: the build-time `no inline script` linter scans each literal independently and only flags a literal that contains BOTH an open and a close tag. By splitting them we keep the literal validation honest while still emitting a valid element at runtime. (This mirrors what framework/uihost does for the routes/catalog JSON blocks.)
Types ¶
type Answer ¶
type Answer struct {
Text string `json:"text"`
// contains filtered or unexported fields
}
Answer is the Schema.org Answer type accepted by Question.
type Article ¶
type Article struct {
Headline string `json:"headline,omitempty"`
Description string `json:"description,omitempty"`
URL string `json:"url,omitempty"`
Image string `json:"image,omitempty"`
DatePublished string `json:"datePublished,omitempty"`
DateModified string `json:"dateModified,omitempty"`
Author *Person `json:"author,omitempty"`
Publisher *Organization `json:"publisher,omitempty"`
// contains filtered or unexported fields
}
Article describes a blog post, news article, or other journalistic item. Drives Google's article rich result.
func NewArticle ¶
func NewArticle() Article
NewArticle returns an Article with the JSON-LD envelope pre-filled.
type BreadcrumbItem ¶
BreadcrumbItem is one rung in a breadcrumb trail.
type BreadcrumbList ¶
type BreadcrumbList struct {
ItemListElement []ListItem `json:"itemListElement"`
// contains filtered or unexported fields
}
BreadcrumbList describes the trail of pages leading to the current one. Each item is a ListItem with Position (1-based) + URL + Name.
func NewBreadcrumbList ¶
func NewBreadcrumbList(items ...BreadcrumbItem) BreadcrumbList
NewBreadcrumbList builds a BreadcrumbList from (name, url) pairs. Positions are assigned 1..N in order.
type FAQPage ¶
type FAQPage struct {
MainEntity []Question `json:"mainEntity"`
// contains filtered or unexported fields
}
FAQPage is a list of Question/Answer pairs. Drives the FAQ rich result (collapsible Q&A under the search hit).
func NewFAQPage ¶
NewFAQPage builds a FAQPage from (question, answer) string pairs.
type ListItem ¶
type ListItem struct {
Position int `json:"position"`
Name string `json:"name"`
Item string `json:"item,omitempty"`
// contains filtered or unexported fields
}
ListItem is one row in an ItemList / BreadcrumbList.
type Offer ¶
type Offer struct {
Price string `json:"price,omitempty"`
PriceCurrency string `json:"priceCurrency,omitempty"`
Availability string `json:"availability,omitempty"`
URL string `json:"url,omitempty"`
// contains filtered or unexported fields
}
Offer represents a price/availability tuple under Product.
type Organization ¶
type Organization struct {
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
Logo string `json:"logo,omitempty"`
// contains filtered or unexported fields
}
Organization describes the publishing entity. Used as the `publisher` of an Article or the `provider` of a Product.
func NewOrganization ¶
func NewOrganization() Organization
NewOrganization returns an Organization with the envelope pre-filled.
type Person ¶
type Person struct {
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
// contains filtered or unexported fields
}
Person describes a human, used as Article author / Review author.
type Product ¶
type Product struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Image string `json:"image,omitempty"`
URL string `json:"url,omitempty"`
Brand string `json:"brand,omitempty"`
Offers *Offer `json:"offers,omitempty"`
// contains filtered or unexported fields
}
Product drives Google's product rich result (price, ratings, etc.).
func NewProduct ¶
func NewProduct() Product
NewProduct returns a Product with the envelope pre-filled.
type Question ¶
type Question struct {
Name string `json:"name"`
AcceptedAnswer *Answer `json:"acceptedAnswer,omitempty"`
// contains filtered or unexported fields
}
Question is the Schema.org Question type used inside FAQPage.
type SearchAction ¶
type SearchAction struct {
Target string `json:"target,omitempty"`
QueryInput string `json:"query-input,omitempty"`
// contains filtered or unexported fields
}
SearchAction declares a sitewide search endpoint. Target accepts a URL template with {search_term_string}.
func NewSearchAction ¶
func NewSearchAction(target string) SearchAction
NewSearchAction returns a SearchAction targeting target with the canonical query-input placeholder.
type Thing ¶
type Thing interface {
// contains filtered or unexported methods
}
Thing is the marker interface that every Schema.org type implements via the embedded base struct.
type WebApplication ¶ added in v0.30.0
type WebApplication struct {
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
Description string `json:"description,omitempty"`
Image string `json:"image,omitempty"`
// ApplicationCategory per schema.org's enumeration, e.g.
// "UtilitiesApplication", "DesignApplication", "BusinessApplication".
ApplicationCategory string `json:"applicationCategory,omitempty"`
// OperatingSystem for web apps is conventionally "Web" or "Any".
OperatingSystem string `json:"operatingSystem,omitempty"`
// BrowserRequirements, e.g. "Requires JavaScript".
BrowserRequirements string `json:"browserRequirements,omitempty"`
Offers *Offer `json:"offers,omitempty"`
// contains filtered or unexported fields
}
WebApplication describes an in-browser application or tool (schema.org SoftwareApplication subtype). The right type for SaaS products, online generators, editors — anything a user runs at a URL. Pair with a free Offer (Price "0") for "free online tool" queries.
func NewWebApplication ¶ added in v0.30.0
func NewWebApplication() WebApplication
NewWebApplication returns a WebApplication with the envelope pre-filled and OperatingSystem defaulted to "Web".
type WebPage ¶
type WebPage struct {
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
Description string `json:"description,omitempty"`
// contains filtered or unexported fields
}
WebPage describes a generic page. Use Article / FAQPage / Product when they fit; WebPage is the fallback.
func NewWebPage ¶
func NewWebPage() WebPage
NewWebPage returns a WebPage with the envelope pre-filled.
type WebSite ¶
type WebSite struct {
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
PotentialAction *SearchAction `json:"potentialAction,omitempty"`
// contains filtered or unexported fields
}
WebSite describes the whole site. Useful at the homepage. Set PotentialAction to wire Google's sitelinks search box.
func NewWebSite ¶
func NewWebSite() WebSite
NewWebSite returns a WebSite with the envelope pre-filled.