Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sitemap filename changed in runtime. #30

Open
boxsnake opened this issue Mar 22, 2019 · 0 comments
Open

Sitemap filename changed in runtime. #30

boxsnake opened this issue Mar 22, 2019 · 0 comments

Comments

@boxsnake
Copy link

boxsnake commented Mar 22, 2019

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 with list- and one start with map-.

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

  1. 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.
  2. Add a *stm.Sitemap.SetNamer() to enable namer customizing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant