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 {
|
type SiteMap struct {
|
||||||
urls []*urlXML
|
urls []*urlXML
|
||||||
BaseURL string
|
BaseURL string
|
||||||
|
MaxURLPerSiteMap int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *SiteMap) AddURL(url string, lastMod *string, freq *ChangeFrequency, prio *float64) {
|
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) {
|
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{}
|
index := &siteMapIndexXML{}
|
||||||
|
|
||||||
for i := 0; i < nSiteMaps; i++ {
|
for i := 0; i < nSiteMaps; i++ {
|
||||||
@@ -83,17 +83,17 @@ func (m *SiteMap) SiteMapIndex() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *SiteMap) SiteMap(id int) ([]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
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
siteMap := &urlSetXML{}
|
siteMap := &urlSetXML{}
|
||||||
|
|
||||||
var urls []*urlXML
|
var urls []*urlXML
|
||||||
if 50000*(id+1) >= len(m.urls) {
|
if m.MaxURLPerSiteMap*(id+1) >= len(m.urls) {
|
||||||
urls = m.urls[50000*id:]
|
urls = m.urls[m.MaxURLPerSiteMap*id:]
|
||||||
} else {
|
} 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...)
|
siteMap.URLs = append(siteMap.URLs, urls...)
|
||||||
|
Reference in New Issue
Block a user