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

add_to_index overwrites index file #354

Open
wordjelly opened this issue Jun 26, 2020 · 2 comments
Open

add_to_index overwrites index file #354

wordjelly opened this issue Jun 26, 2020 · 2 comments

Comments

@wordjelly
Copy link

Hi,
I have a situation where I wish to "update" the sitemap index file, adding more links to it,over time. We have a lot of dynamic content generation on our site.

When I do the following:

SitemapGenerator::Sitemap.create do
    add_to_index "/new_sitemap.xml.gz"
end

I find that it overwrites the old sitemap index file.
Any links that were present in the older sitemap index are gone,and now I only have one link with "new_sitemap.xml.gz" in the index.

How do I update the index file, so that it preserves older links?

Thanks.

@kjvarga
Copy link
Owner

kjvarga commented Jun 26, 2020

@wordjelly there is no mechanism for updating a sitemap. Because sitemaps are XML files, there is no easy way to do that. You could write something yourself, but the general approach is to just regenerate your entire sitemap periodically (as often as you need to). That is the simplest approach. Sometimes people will generate sitemap files for only the new content since the last run (and ensure that the new files don't replace existing ones), then regenerate only the index by adding links for each of the old sitemaps, and the new sitemap(s). Otherwise you will have to parse the XML index file, add the new links and rewrite the file.

Unless you have millions of links and/or are needing to add content multiple times a day, by far the simplest is to just regenerate each time.

@wordjelly
Copy link
Author

Would you be open to a PR on this ? I thought, just like "add_to_index" , we could have an API method "update_index". Let me know and I'll close this.

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

2 participants