Back to godoc.org
github.com/kataras/sitemap

package sitemap

v0.0.5
Latest Go to latest
Published: Dec 11, 2019 | License: MIT | Module: github.com/kataras/sitemap

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.

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder is the sitemaps Builder.

func New

func New(startURL string) *Builder

New returns a new sitemaps Builder. Use its `Add` to add one or more urls and `Build` once.

func (*Builder) Build

func (b *Builder) Build() (handlers []*Handler)

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

func (b *Builder) DefaultLang(langCode string) *Builder

DefaultLang sets the default "hreflang" attribute of a self-included URL Link.

func (*Builder) ErrorHandler

func (b *Builder) ErrorHandler(fn func(err error) (handled bool)) *Builder

ErrorHandler sets the error handler.

func (*Builder) URL

func (b *Builder) URL(sitemapURLs ...URL) *Builder

URL adds a location of a Sitemap file determines the set of URLs that can be included in that Sitemap.

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

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)
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,allowempty,omitempty"`
}

URL is the parent tag for each URL entry.

func (u *URL) AddLink(link Link)

AddLink adds a link to this URL.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
f or F : Jump to identifier