I use a meteorite to create a simple blog system. For sitemaps, I use this package.
I added some initialized data to the server start function (I create a message) and used the code below ( server / sitemaps.js ) on the server to create sitemaps for each category (for example, sitemap1.xml for the first category, etc.):
function sitemapOutput(categoryName){ var out = [], posts = Posts.find({ category: categoryName }).fetch(); _.each(posts, function(post) { out.push({ page: post.url(), lastmod: post.insertDate, changefreq: 'weekly' }); }); return out; } Categories.find().forEach(function(Category, index) { sitemaps.add('/sitemap' + (index+1) +'.xml', function(){ return sitemapOutput(Category.name); }); });
And I have a launch like this: ( server / startup.js )
Meteor.startup(function () {
But the Sitemaps did not exist before the server rebooted (my robots.txt files were also empty), but when the server restarted the Sitemaps and the robots.txt content created for me.
I think the messages are inserted after sitemaps.js, but what are the guys problems and how to fix it?
New attempt:
I am trying a new solution as shown below, but this code also does not work. (I want to create a separate sitemap for each category 10000 to prevent a large sitemap and Sitemap error for google site):
for (var i=0;i<=Math.round(Categories.find().count()/10000);i++) { sitemaps.add('/sitemap' + i +'.xml', function(){ var out = []; Categories.find({}, {sort: {insertDate: 1} ,limit: 10000, skip: i * 10000}).forEach(function(Category) { out.push({ page: "/category/" + Category.title + "/" + Category._id, lastmod: Category.insertDate, changefreq: 'weekly' }); }); return out; }); }
robots.txt displays Sitemaps correctly, but the entire sitemap is empty:
<urlset> </urlset>
When is sitemaps.add () executed? I think this happens when the server restarts, but the new attempt was disappointed by me, and I think my guess is wrong and if the sitemaps.add () file was run, why is it empty.