package lazyseo

import "golazy.dev/lazyseo"

Package lazyseo renders common document metadata for GoLazy views and other lazyview renderers.

The package owns the metadata values that normally appear in an HTML document head: the page title, description, author, language, canonical URL, alternate URLs, social sharing tags, article timestamps, and schema.org JSON-LD. A canonical URL is the preferred permanent URL for the current content; use it when the same page can be reached through more than one path or query string. Alternate URLs describe other language, media, or format versions. JSON-LD is structured data encoded as a <script type="application/ld+json"> element so search and social crawlers can understand the page as an article, product, organization, or another schema type.

lazyapp installs Helpers automatically after it creates the lazyview renderer. The application-wide defaults come from lazyapp.Config.SEO, and those defaults are merged with request-local metadata before the helpers render. Layouts can call {{seo}} inside <head> and {{seo_lang}} on the html element. lazycontroller.Base exposes SEO, Title, Description, Canonical, Alternate, Kind, OpenGraph, TwitterCard, JSONLD, and related convenience methods that store request-local metadata for those helpers. lazycontroller.Base.Metadata can also read small metadata methods from a model and fill lazyseo.Meta.

Use PageKind values such as Article or WebPage when one choice should set both Open Graph and schema.org names. Use OpenGraphType, SchemaType, and the OpenGraph or TwitterCard structs when a crawler-specific escape hatch is needed. The lazyseo/jsonld subpackage contains small schema.org value types for common JSON-LD payloads, and DefaultJSONLD builds a conventional payload from a Meta value when lazycontroller.Metadata has enough information.

lazyseo does not generate robots.txt or sitemap.xml files. Robots directives tell crawlers which paths should be crawled, and sitemaps list canonical URLs that should be discovered; those are site-level documents owned by an application or a future routing/indexing package. This package only renders metadata for the current view.

The package can also be used directly with any value that supports Set(string, any), or by passing a "seo" variable to lazyview. That keeps metadata rendering independent from controller internals and from a specific template engine.

Variables

var WebPage, WebSite, Article, BlogPosting, NewsArticle, Product, Profile, Book, Video, MusicSong, MusicAlbum, Place, Restaurant, Organization

var (
	WebPage		= PageKind{OpenGraph: "website", Schema: "WebPage"}
	WebSite		= PageKind{OpenGraph: "website", Schema: "WebSite"}
	Article		= PageKind{OpenGraph: "article", Schema: "Article"}
	BlogPosting	= PageKind{OpenGraph: "article", Schema: "BlogPosting"}
	NewsArticle	= PageKind{OpenGraph: "article", Schema: "NewsArticle"}
	Product		= PageKind{OpenGraph: "product", Schema: "Product"}
	Profile		= PageKind{OpenGraph: "profile", Schema: "ProfilePage"}
	Book		= PageKind{OpenGraph: "book", Schema: "Book"}
	Video		= PageKind{OpenGraph: "video.other", Schema: "VideoObject"}
	MusicSong	= PageKind{OpenGraph: "music.song", Schema: "MusicRecording"}
	MusicAlbum	= PageKind{OpenGraph: "music.album", Schema: "MusicAlbum"}
	Place		= PageKind{OpenGraph: "place", Schema: "Place"}
	Restaurant	= PageKind{OpenGraph: "place", Schema: "Restaurant"}
	Organization	= PageKind{OpenGraph: "website", Schema: "Organization"}
)

Functions

func DefaultJSONLD

DefaultJSONLD builds a conventional schema.org value from metadata.

func DefaultJSONLD(meta Meta) any

func Helpers

Helpers returns the template helpers provided by lazyseo.

func Helpers(defaults ...Option) map[string]any

Types

type Alternate

Alternate describes an alternate URL for the current page.

type Alternate struct {
	Language	string
	URL		string
	Media		string
	Type		string
	Title		string
}

type Meta

Meta contains the metadata emitted by the seo view helper.

type Meta struct {
	Title		string
	SiteName	string
	Description	string
	Author		string
	Language	string
	URL		string
	Canonical	string
	Alternates	[]Alternate
	Image		string
	ImageAlt	string
	OpenGraph	OpenGraph
	Type		string
	SchemaType	string
	Locale		string
	Twitter		TwitterCard
	TwitterType	string
	JSONLD		[]any
	PublishedTime	time.Time
	UpdatedTime	time.Time
}
func New

New builds Meta with the supplied options.

func New(options ...Option) *Meta
func Set

Set stores request-local SEO metadata on a controller.

func Set(controller setter, options ...Option) *Meta

type OpenGraph

OpenGraph overrides metadata emitted for Open Graph tags.

type OpenGraph struct {
	Title		string
	Description	string
	URL		string
	Image		string
	ImageAlt	string
	ImageWidth	int
	ImageHeight	int
	Type		string
	SiteName	string
	Locale		string
}

type Option

Option configures Meta values.

type Option func(*Meta)
func AlternateURL
func AlternateURL(language, url string) Option
func Author
func Author(value string) Option
func Canonical
func Canonical(value string) Option
func Description
func Description(value string) Option
func Image
func Image(value string) Option
func ImageAlt
func ImageAlt(value string) Option
func JSONLD
func JSONLD(value any) Option
func Kind
func Kind(kind PageKind) Option
func Language
func Language(value string) Option
func LastUpdated
func LastUpdated(value time.Time) Option
func Locale
func Locale(value string) Option
func OpenGraphData
func OpenGraphData(value OpenGraph) Option
func OpenGraphType
func OpenGraphType(value string) Option
func PublishedTime
func PublishedTime(value time.Time) Option
func SchemaType
func SchemaType(value string) Option
func SiteName
func SiteName(value string) Option
func Title
func Title(value string) Option
func TwitterCardData
func TwitterCardData(value TwitterCard) Option
func TwitterCardType
func TwitterCardType(value string) Option
func Type
func Type(value string) Option
func URL
func URL(value string) Option
func UpdatedTime
func UpdatedTime(value time.Time) Option

type TwitterCard

TwitterCard overrides metadata emitted for Twitter card tags.

type TwitterCard struct {
	Card		string
	Title		string
	Description	string
	Image		string
	ImageAlt	string
	Site		string
	Creator		string
}

Directories

Path Synopsis
lazyseo/jsonld Package jsonld provides small schema.org JSON-LD value types for lazyseo.