Generates sitemaps and index files based on the sitemaps.org protocol.
Creates a new group of sitemaps that used a common name.
group := sitemap.NewSitemapGroup("/var/www/blog/public/sitemaps/","blog")
If the sitemap exceed the limit of 50k urls, new sitemaps will have a numeric suffix to the name. Example:
- blog_1.xml.gz
- blog_2.xml.gz
Add sitemap.URL to group
now := time.Now()
group.Add(sitemap.URL{
Loc: "http://example.com/blog/1/",
ChangeFreq: sitemap.Hourly,
LastMod: &now,
Priority: 0.9
})
Handle the rest of the url that has not been added to any sitemap and add, in addition to clean variables and close the channel group
if you use several groups of sitemap is safer use this function to close all groups for you before creating the index. Returns a channel with the done signal.
//release after close all groups
<-sitemap.CloseGroups(group, group2)
//generate index - by last execution paths
savedSitemaps := group.GetSavedSitemaps()
sitemapsgroup2 := group.GetSavedSitemaps()
savedSitemaps = append(savedSitemaps, sitemapsgroup2...)
Currently we have 2 ways to create the index, searching for files in the directory or passing a slice of urls to sitemaps. To generate the slice of sitemaps generated in the last run we GetSavedSitemaps function.
Returns an array of urls in the sitemaps created script execution
savedSitemaps := group.GetSavedSitemaps()
index := sitemap.CreateIndexBySlice(savedSitemaps, "http://example.com.br/sitemaps/")
#####OR
Search all the xml.gz sitemaps_dir directory, uses the modified date of the file as lastModified
path_index is included for the function does not include the url of the index in your own content, if it is present in the same directory.
index := sitemap.CreateIndexByScanDir("/var/www/blog/public/sitemaps/", "/var/www/blog/public/index.xml.gz", "http://example.com.br/sitemaps/")
Warning: this release do not control old sitemaps, when using this method the index can be created with sitemaps that are no longer used. In case you need to delete manually.
creates and gzip the xml index
sitemap.CreateSitemapIndex("/var/www/blog/public/index.xml.gz", index)
Sends a ping to search engines indicating that the index has been updated.
Currently supports Google and Bing.
sitemap.PingSearchEngines("http://exemple.com/index.xml.gz")
There is a very simple example of using the example folder.