nextjs generate sitemap
nextjsTo generate a sitemap for a Next.js app, you can use the sitemap module. This module allows you to create a sitemap for your app by specifying the routes that should be included in the sitemap.
To use the sitemap module, you will first need to install it:
npm install sitemap
Once the module is installed, you can use it to generate a sitemap for your app by creating a script that defines your routes and then calling the createSitemap function:
const Sitemap = require('sitemap');
const routes = [
'/',
'/about',
'/contact'
];
const sitemap = Sitemap.createSitemap({
hostname: 'https://www.example.com',
cacheTime: 600000, // 600 sec - cache purge period
urls: routes.map(path => {
return { url: path, changefreq: 'weekly', priority: 0.5 };
})
});
sitemap.toXML((err, xml) => {
if (err) {
console.error(err);
return;
}
console.log(xml);
});
This script will generate an XML sitemap for the routes specified in the routes array. You can then save the XML sitemap to a file or serve it dynamically from your app.
For more information on the sitemap module, you can check out the documentation.
Other Article on Tag nextjs
- - fetch function mode sors, no-cors, same-origin
- - fetch request option
- - How to add Bootstrap in Next.js
- - how to minimize front in next js
- - nextjs add bootstrap
- - nextjs add Font Awesome
- - nextjs add font face in head
- - nextjs add prismjs
- - nextjs add Syntax highlighting code
- - nextjs call api