2 Commits

Author SHA1 Message Date
ec86a0396a fixed multiple slashes in path 2023-03-03 21:01:05 +01:00
ccf681abfc fixed paths; protect against out-of-bounds 2023-03-03 20:42:02 +01:00

View File

@@ -4,6 +4,7 @@ import (
"encoding/xml"
"fmt"
"math"
"path"
)
type ChangeFrequency string
@@ -51,7 +52,7 @@ type SiteMap struct {
func (m *SiteMap) AddURL(url string, lastMod *string, freq *ChangeFrequency, prio *float64) {
m.urls = append(m.urls, &urlXML{
Loc: fmt.Sprintf("https://%s/%s", m.BaseURL, url),
Loc: fmt.Sprintf("https://%s", path.Join(m.BaseURL, url)),
LastMod: lastMod,
ChangeFreq: freq,
Priority: prio,
@@ -69,7 +70,7 @@ func (m *SiteMap) SiteMapIndex() ([]byte, error) {
for i := 0; i < nSiteMaps; i++ {
index.SiteMaps = append(index.SiteMaps, &sitemapXML{
Loc: fmt.Sprintf("https://%s/sitemap%d.xml", m.BaseURL, i),
Loc: fmt.Sprintf("https://%s/sitemap/%d", m.BaseURL, i),
})
}
@@ -82,6 +83,10 @@ func (m *SiteMap) SiteMapIndex() ([]byte, error) {
}
func (m *SiteMap) SiteMap(id int) ([]byte, error) {
if 50000*(id) >= len(m.urls) {
return nil, nil
}
siteMap := &urlSetXML{}
var urls []*urlXML