【发布时间】:2015-11-07 08:10:49
【问题描述】:
我正在使用流星创建简单的博客系统。对于站点地图文件,我使用this 包。
我在服务器启动功能(创建一些帖子)中添加了一些初始化数据,并在服务器中使用以下代码(server/sitemaps.js)为每个类别创建站点地图(例如,首先使用 sitemap1.xml类别等):
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); });
});
我有这样的启动:(server/startup.js)
Meteor.startup(function () {
// some post and category created here
});
但是站点地图在服务器重新启动之前不存在(我的 robots.txt 文件也是空的)但是当服务器重新启动站点地图和为我创建的 robots.txt 内容时。
我认为是在 sitemaps.js 之后插入的帖子,但问题是什么?如何解决?
新尝试:
我尝试了如下的新解决方案,但此代码也不起作用。 (我想为每个 10000 个类别创建单独的站点地图文件,以防止大站点地图和谷歌站点地图错误):
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 正确显示站点地图文件,但所有站点地图都是空的,如下所示:
<urlset> </urlset>
sitemaps.add() 何时运行?我认为它会在服务器重新启动时发生,但 New try 让我很失望,我认为我的猜测是不正确的,如果运行了 sitemaps.add() 为什么它是空的。
【问题讨论】:
-
你的文件夹结构是什么样的?
-
我描述的有问题。我在服务器文件夹中有一个 sitemaps.js
标签: javascript node.js meteor sitemap