Documentation ¶
Overview ¶
Package sitemap implements the Sitemap Protocol. Reference: https://www.sitemaps.org/protocol.html
Index ¶
Constants ¶
const ( Always = "always" Hourly = "hourly" Daily = "daily" Weekly = "weekly" Monthly = "monthly" Yearly = "yearly" Never = "never" )
URL.ChangeFreq valid values.
const DefaultLang = "en"
DefaultLang is the default "hreflang" attribute of a self-included Link child element of URL.
Variables ¶
var MaxURLsPerSitemap = 50000
MaxURLsPerSitemap is the limit of each sitemap, if more than number of urls are registered then sitemaps are automatically splitted and a sitemap index will be used. Defaults to 50000 as Sitemap Protocol specifies.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is the sitemaps Builder.
func New ¶
New returns a new sitemaps Builder. Use its `Add` to add one or more urls and `Build` once.
func (*Builder) Build ¶
Build builds the sitemaps based on previous `Builder#URL` calls. It returns a list of sitemap Handlers. Each `Handler` is compatible with `net/http#Handler` and it contains further like the `Path`, `Pos` and if it's a sitemaps index handler.
func (*Builder) DefaultLang ¶ added in v0.0.4
DefaultLang sets the default "hreflang" attribute of a self-included URL Link.
func (*Builder) ErrorHandler ¶
ErrorHandler sets the error handler.
type Handler ¶
type Handler struct { // Content returns the raw xml data. Content []byte // Pos returns the position, starting from 0. Pos int // Path returns the request path that this handler should be listening on. Path string // IsSitemapIndex reports whether this handler serves a Sitemap Index File. IsSitemapIndex bool }
Handler is a sitemap handler. The result of `Builder#Build`.
type Link ¶ added in v0.0.4
type Link struct { Rel string `xml:"rel,attr"` Hreflang string `xml:"hreflang,attr"` Href string `xml:"href,attr"` }
Link is the optional child element of a URL. It can be used to list every alternate version of the page.
Read more at: https://support.google.com/webmasters/answer/189077?hl=en.
type URL ¶
type URL struct { // Loc is required. It defines the URL of the page. // This URL must begin with the protocol (such as http) and end with a trailing slash, // if your web server requires it. This value must be less than 2,048 characters. // Read more at: https://www.sitemaps.org/protocol.html#location Loc string `xml:"loc"` // LastMod is optional. It is the date of last modification of the file. LastMod time.Time `xml:"-"` // LastModStr do NOT set it directly, // other solution would be to use ptr or custom time marshaler but this will ruin the API's expressiveness. // // See internal `sitemap#Add`. LastModStr string `xml:"lastmod,omitempty"` // ChangeFreq is optional. Defines how frequently the page is likely to change. // This value provides general information to search engines and may not correlate exactly to how often they crawl the page. // Valid values are: // "always" // "hourly" // "daily" // "weekly" // "monthly" // "yearly" // "never" ChangeFreq string `xml:"changefreq,omitempty"` // Priority is optional. It defines the priority of this URL relative to other URLs on your site. // Valid values range from 0.0 to 1.0. // // The default priority of a page is 0.5. Priority float32 `xml:"priority,omitempty"` Links []Link `xml:"xhtml:link,omitempty"` }
URL is the parent tag for each URL entry.