ekalinin/sitemap.js

[ BUG ] Sitemap not generated when url count is less than 5.

vikaskrsharma opened this issue · 3 comments

When generating a sitemap xml using SitemapStream and if number of items write is less than 5 ie number of items passed for url generation is less than 5, generated xml does not show any data. For 5 or more item/urls, it is working fine.

Do you have example code for this?

I ask because:

  • There is literally a test that writes 2 items:
    it('pops out the preamble and closetag', async () => {
    const sms = new SitemapStream();
    sms.write(sampleURLs[0]);
    sms.write(sampleURLs[1]);
    sms.end();
    expect((await streamToPromise(sms)).toString()).toBe(
    preamble +
    `<url><loc>${sampleURLs[0]}/</loc></url>` +
    `<url><loc>${sampleURLs[1]}</loc></url>` +
    closetag
    );
    });
  • I suspect this is a usage error that will be obvious if we can see the example code
  • I have a production system that has been writing arbitrary numbers of items to new sitemap files and has not had an error in 2+ years... not a guarantee that there is no problem, but I think this is pretty solid
  • I am aware that there are lots of gotchas with streams that can cause subtle problems

@derduher - I think we can close this as a duplicate of #362

@huntharo As i am not working on this project anymore, can't paste the code. but the case was, if i am passing less than 5 url to the SitemapStream, i am getting nothing in sitemap url. but i pass 6 or more url, i was getting sitemap with all urls. As per your test, this case should fail. but when was using it on my env, this was the actual behaviour.