go-sitemap-generator
go-sitemap-generator copied to clipboard
Sitemap filename changed in runtime.
Situation
In my situation, I am going to build a sitemap with following sub files:
-
sitemap.xml
<- Sitemap Index File -
sitemap/list-1.xml
-
sitemap/list-2.xml
- ...,
-
sitemap/list-n.xml
-
sitemap/map-1.xml
-
sitemap/map-2.xml
- ...
-
sitemap/map-n.xml
It has two groups: one starts withlist-
and one start withmap-
.
In this case, I set the Filename and then call *stm.Sitemap.Create()
for each group.
However, the filename generator seems from *stm.Sitemap.Options.nmr
, which is not reset when the filename is changed.
Hope to be fixed soon.
Code I am using
package main
import "github.com/ikeikeikeike/go-sitemap-generator/stm"
func main() {
... // Omit unimportant codes
sm := stm.NewSitemap(0)
sm.SetDefaultHost(conf.Sitemap.Host)
sm.SetPublicPath(pubPath)
sm.SetSitemapsPath("sitemap")
sm.SetCompress(false)
sm.SetPretty(conf.Sitemap.Pretty)
sm.SetVerbose(conf.Sitemap.Verbose)
// For `list-*`
sm.SetFilename("list-")
sm = sm.Create()
for _, v := range list {
sm.Add(...)
}
sm = sm.Finalize()
// For `map-*`
sm.SetFilename("map-")
sm = sm.Create()
for _, v := range list {
sm.Add(...)
}
sm = sm.Finalize()
}
Expected to Get
In sitemap/
:
-
list-1.xml
-
list-2.xml
-
list-3.xml
-
map-1.xml
-
map-2.xml
Actual Got
In sitemap/
:
-
list-1.xml
-
list-2.xml
-
list-3.xml
-
list-4.xml
<- This seems created by namer in options, and the namer is not re-created when changing the filename -
list-5.xml
Proper solutions
- Add a
opt.nmr = nil
at the end of*stm.Sitemap.SetFilename()
, so that when calling*stm.Sitemap.Create()
again, the namer will be recreated. - Add a
*stm.Sitemap.SetNamer()
to enable namer customizing.