sitemap: github.com/kataras/sitemap Index | Files

package sitemap

import "github.com/kataras/sitemap"

Package sitemap implements the Sitemap Protocol. Reference: https://www.sitemaps.org/protocol.html

Index

Package Files

doc.go sitemap.go

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 Uses

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

Builder is the sitemaps Builder.

func New Uses

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 Uses

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 Uses

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

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

func (*Builder) ErrorHandler Uses

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

ErrorHandler sets the error handler.

func (*Builder) URL Uses

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 Uses

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 Uses

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 Uses

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.

Package sitemap imports 6 packages (graph) and is imported by 4 packages. Updated 2019-12-12. Refresh now. Tools for package owners.