0
私はexpress-sitemapミドルウェアを使用して自分のウェブサイトのサイトマップを生成しようとしています。次のように私のコードは次のとおりです。(ノード/ 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をユーザーに提供することをどのように提案しますか?