meteor-sitemaps icon indicating copy to clipboard operation
meteor-sitemaps copied to clipboard

Dynamic update sitemap.xml when DB collection updated

Open vasilisach opened this issue 6 years ago • 6 comments

Is sitemap change, if db collection changed (which use to sitemap)? For example, is sitemap update, if WikiPages was updated?

sitemaps.add('/mw_AllPages_sitemap.xml.gz', function(req) { var out = [], pages = WikiPages.find().fetch(); _.each(pages, function(page) { out.push({ page: 'read/' + page.name, lastmod: page.lastUpdated }); }); return out; });

vasilisach avatar Apr 14 '20 06:04 vasilisach

Yes, that's right. The function(req) {...} is called, and the sitemap generated, at request time. As such the provided sitemap is always "up-to-date" w.r.t. the database.

gadicc avatar Apr 14 '20 06:04 gadicc

Is this function function(req) {...} called once? I created the file sitemap.js according to the instructions and once call sitemaps.add(). Is a sitemap reactively updated or only if I called sitemaps.add() again?

vasilisach avatar Apr 14 '20 06:04 vasilisach

You only need to call sitemaps.add() once. function(req) {...} is called every time a request is made to the sitemap url, and returns the information from that call.

It's not quite right to say that it's updated "reactively" but it has the same effect. It's not "reactive" because nothing runs as soon as you change the data. Rather, the data is requested on every request, so it's always "up-to-date".

gadicc avatar Apr 14 '20 08:04 gadicc

You only need to call sitemaps.add() once. function(req) {...} is called every time a request is made to the sitemap url, and returns the information from that call.

It's not quite right to say that it's updated "reactively" but it has the same effect. It's not "reactive" because nothing runs as soon as you change the data. Rather, the data is requested on every request, so it's always "up-to-date".

Thank you, I'm understand

vasilisach avatar Apr 14 '20 08:04 vasilisach

This is enough for search engines?Maybe I need regularly to do request to sitemap.xml to update it?

vasilisach avatar Apr 14 '20 08:04 vasilisach

Yup, it was created specifically for the search engines. How often it's checked depends on the individual search engine. The engines will continuously monitor your sitemaps on their own without any further action on your part, possibly influenced by the changefreq parameter for each page.

While it is usually possible to manually request a recheck by the search engine, this is usually only necessary to urgently correct big mistakes (or after adding your sitemap for the first time).

gadicc avatar Apr 14 '20 08:04 gadicc