結論
output: 'export'でのサイトマップ生成はなぜかNext.jsは対応していません。
なので、少々ハックな方法を使うことが必要です。
方法
/app/sitemap.xml/route.tsを追加する。
function getSitemap() {
const map = [
{
url: 'https://my.app.url',
lastModified: new Date(),
changeFrequency: 'daily',
priority: 1,
}
];
return `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
${map
.map(
(item) => `
<url>
<loc>${item.url}</loc>
<lastmod>${item.lastModified.toISOString()}</lastmod>
<changefreq>${item.changeFrequency}</changefreq>
<priority>${item.priority}</priority>
</url>
`,
)
.join('')}
</urlset>
`;
}
export async function GET() {
return new Response(getSitemap(), {
headers: {
'Content-Type': 'text/xml',
},
});
}
参考(ほぼ翻訳元)
お気持ち
Next.jsは便利だが無駄に複雑だったりこんな感じの「このモードだとサポートしていません。」みたいなことが良くあります。(というように感じます。)
みんながたくさん使うので機能が増えすぎているのでしょう。あまり好きではありません。