0
我正在嘗試使用快速站點地圖中間件爲我的網站生成站點地圖。我的代碼如下:(Node/Express)快速站點地圖生成不正確的站點地圖
var sitemap = require('express-sitemap')();
//...
app.get('/', function(req, res) {
res.render('index')
})
//...
posts = [
post2 = {
"url":
"wild-birds",
},
post1 = {
"url":
"top-dogs-cats",
}
]
app.get('/:leg', function(req, res, next) {
for (i=0; i<posts.length; i++) {
if (req.params.leg == posts[i].url) {
res.render('post', { posts2:posts[i] });
}
}
//The above code checks to see which blog post was requested by
//the user, and responds by rendering the associated HTML (with some
//additional information I chose to exclude from this post)
})
console.log(sitemap.generate(app))
此輸出:
{ '/': [ 'get' ],
'/:leg': [ 'get' ] }
當它應該是輸出:
{ '/': [ 'get' ],
'/wild-birds': [ 'get' ],
'/top-dogs-cats': [ 'get' ]
}
我應該如何去解決這個網站地圖生成器?此外,你會如何建議將更正的sitemap.xml提供給用戶?