make sitemap url limit adjustable
This commit is contained in:
16
sitemap.go
16
sitemap.go
@@ -46,8 +46,9 @@ type sitemapXML struct {
|
||||
}
|
||||
|
||||
type SiteMap struct {
|
||||
urls []*urlXML
|
||||
BaseURL string
|
||||
urls []*urlXML
|
||||
BaseURL string
|
||||
MaxURLPerSiteMap int
|
||||
}
|
||||
|
||||
func (m *SiteMap) AddURL(url string, lastMod *string, freq *ChangeFrequency, prio *float64) {
|
||||
@@ -64,8 +65,7 @@ func prefixXML(content []byte) []byte {
|
||||
}
|
||||
|
||||
func (m *SiteMap) SiteMapIndex() ([]byte, error) {
|
||||
nSiteMaps := int(math.Floor(float64(len(m.urls))/50000 + 1))
|
||||
|
||||
nSiteMaps := int(math.Floor(float64(len(m.urls))/float64(m.MaxURLPerSiteMap) + 1))
|
||||
index := &siteMapIndexXML{}
|
||||
|
||||
for i := 0; i < nSiteMaps; i++ {
|
||||
@@ -83,17 +83,17 @@ func (m *SiteMap) SiteMapIndex() ([]byte, error) {
|
||||
}
|
||||
|
||||
func (m *SiteMap) SiteMap(id int) ([]byte, error) {
|
||||
if 50000*(id) >= len(m.urls) {
|
||||
if m.MaxURLPerSiteMap*(id) >= len(m.urls) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
siteMap := &urlSetXML{}
|
||||
|
||||
var urls []*urlXML
|
||||
if 50000*(id+1) >= len(m.urls) {
|
||||
urls = m.urls[50000*id:]
|
||||
if m.MaxURLPerSiteMap*(id+1) >= len(m.urls) {
|
||||
urls = m.urls[m.MaxURLPerSiteMap*id:]
|
||||
} else {
|
||||
urls = m.urls[50000*id : 50000*(id+1)]
|
||||
urls = m.urls[m.MaxURLPerSiteMap*id : m.MaxURLPerSiteMap*(id+1)]
|
||||
}
|
||||
|
||||
siteMap.URLs = append(siteMap.URLs, urls...)
|
||||
|
Reference in New Issue
Block a user