Documentation ¶
Index ¶
- Constants
- Variables
- func IsIndex(data []byte) bool
- type ChangeFrequency
- type Index
- type LastModification
- type Location
- type Priority
- type Sitemap
- func CrawlHostname(hostname string, current *Sitemap) (*Sitemap, error)
- func Fetch(url string) (*Sitemap, error)
- func New() *Sitemap
- func ParseXML(data []byte) (*Sitemap, error)
- func ParseXMLIndex(data []byte) (*Sitemap, error)
- func ParseXMLURLSet(data []byte) (*Sitemap, error)
- func ReadXML(r io.Reader) (*Sitemap, error)
- func ReadXMLFile(name string) (*Sitemap, error)
- func (s *Sitemap) GetURL(loc string) *URL
- func (s *Sitemap) IsIndex() bool
- func (s *Sitemap) RemoveURL(loc string)
- func (s *Sitemap) SetURL(u *URL)
- func (s *Sitemap) Size() int
- func (s *Sitemap) SortByLocation()
- func (s *Sitemap) String() string
- func (s *Sitemap) ToTXT() ([]byte, error)
- func (s *Sitemap) ToXML() ([]byte, error)
- func (s *Sitemap) ToXMLIndent() ([]byte, error)
- type URL
- type URLSet
Examples ¶
Constants ¶
const XMLNameSpace = "http://www.sitemaps.org/schemas/sitemap/0.9"
Variables ¶
var (
ErrSitemapIndex = errors.New("sitemap is index")
)
Functions ¶
Types ¶
type ChangeFrequency ¶
type ChangeFrequency []byte
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
The value "always" should be used to describe documents that change each time they are accessed. The value "never" should be used to describe archived URLs.
Please note that the value of this tag is considered a hint and not a command. Even though search engine crawlers may consider this information when making decisions, they may crawl pages marked "hourly" less frequently than that, and they may crawl pages marked "yearly" more frequently than that. Crawlers may periodically crawl pages marked "never" so that they can handle unexpected changes to those pages.
Example:
<changefreq>monthly</changefreq>
var ( ChangeFrequencyAlways ChangeFrequency = []byte("always") ChangeFrequencyHourly ChangeFrequency = []byte("hourly") ChangeFrequencyDaily ChangeFrequency = []byte("daily") ChangeFrequencyWeekly ChangeFrequency = []byte("weekly") ChangeFrequencyMonthly ChangeFrequency = []byte("monthly") ChangeFrequencyYearly ChangeFrequency = []byte("yearly") ChangeFrequencyNever ChangeFrequency = []byte("never") )
Valid values for ChangeFrequency
func (ChangeFrequency) IsValid ¶
func (c ChangeFrequency) IsValid() bool
ParseChangeFrequency parses ChangeFrequency from v.
If v is not a valid value for ChangeFrequency, returns nil.
func (ChangeFrequency) String ¶
func (c ChangeFrequency) String() string
type Index ¶
type Index struct { XMLName xml.Name `xml:"sitemapindex"` NameSpace string `xml:"xmlns,attr"` Sitemap []URL `xml:"sitemap"` }
Index encapsulates information about all of the Sitemaps in the file.
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <sitemap> <loc>http://www.example.com/sitemap1.xml.gz</loc> <lastmod>2004-10-01T18:23:17+00:00</lastmod> </sitemap> <sitemap> <loc>http://www.example.com/sitemap2.xml.gz</loc> <lastmod>2005-01-01</lastmod> </sitemap> </sitemapindex>
type LastModification ¶
type LastModification []byte
The date of last modification of the page. This date should be in W3C Datetime format. This format allows you to omit the time portion, if desired, and use YYYY-MM-DD.
Note that the date must be set to the date the linked page was last modified, not when the sitemap is generated.
Note also that this tag is separate from the If-Modified-Since (304) header the server can return, and search engines may use the information from both sources differently.
Example:
<lastmod>2005-01-01</lastmod>
func (LastModification) String ¶
func (l LastModification) String() string
type Location ¶
type Location []byte
Location is 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.
Example:
<loc>http://www.example.com/</loc>
type Priority ¶
type Priority []byte
The priority of this URL relative to other URLs on your site. Valid values range from 0.0 to 1.0. This value does not affect how your pages are compared to pages on other sites—it only lets the search engines know which pages you deem most important for the crawlers.
The default priority of a page is 0.5.
Please note that the priority you assign to a page is not likely to influence the position of your URLs in a search engine's result pages. Search engines may use this information when selecting between URLs on the same site, so you can use this tag to increase the likelihood that your most important pages are present in a search index.
Also, please note that assigning a high priority to all of the URLs on your site is not likely to help you. Since the priority is relative, it is only used to select between URLs on your site.
Example:
<priority>0.8</priority>
type Sitemap ¶
type Sitemap struct { URL []URL // contains filtered or unexported fields }
func Fetch ¶
Fetch fetches the Sitemap from url.
If fetch fails, returns the status code as an error (eg.: "404").
func ParseXMLIndex ¶
func ParseXMLURLSet ¶
func ReadXMLFile ¶
ReadFile reads the Sitemap from file the named file.
func (*Sitemap) SortByLocation ¶
func (s *Sitemap) SortByLocation()
SortByLocation sorts the URLs by Location in ascending order.
func (*Sitemap) ToXMLIndent ¶
type URL ¶
type URL struct { Location Location `xml:"loc"` LastMod LastModification `xml:"lastmod,omitempty"` ChangeFreq ChangeFrequency `xml:"changefreq,omitempty" ` Priority Priority `xml:"priority,omitempty" ` }
URL is the parent tag for each URL entry. The remaining tags are children of this tag.
<url> <loc>http://www.example.com/</loc> <lastmod>2005-01-01</lastmod> <changefreq>monthly</changefreq> <priority>0.8</priority> </url>
func NewURL ¶
NewURL returns a new URL with the given fields set. If any field is nil, it will be omitted.
Example ¶
package main import ( "fmt" "git.gorbe.io/go/sitemap" ) func main() { u := sitemap.NewURL("https://example.com"). SetLastmodification("1970-01-01"). SetChangeFrequency(sitemap.ChangeFrequencyNever.String()). SetPriority("1.0") fmt.Printf("%s\n", u) }
Output: https://example.com 1970-01-01 never 1.0
func (*URL) SetChangeFrequency ¶
SetChangeFrequency clones changefreq to u.ChangeFreq and returns u.
If URL u is nil, returns nil.
func (*URL) SetLastmodification ¶
SetLastmodification clones lastmod to u.LastMod and returns u.
If URL u is nil, returns nil.
func (*URL) SetPriority ¶
SetPriority clones priority to u.Priority and returns u.
If URL u is nil, returns nil.
type URLSet ¶
type URLSet struct { XMLName xml.Name `xml:"urlset"` NameSpace string `xml:"xmlns,attr"` URL []URL `xml:"url"` }
URLSet encapsulates the file and references the current protocol standard.
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>http://www.example.com/</loc> <lastmod>2005-01-01</lastmod> <changefreq>monthly</changefreq> <priority>0.8</priority> </url> </urlset>