npm install @nuxtjs/sitemap --save
Create createRoute.js
file in /utils folder. /utils folder is not default folder by NuxtJS. So you can create it by manual.
Than add source code like bellow. This source code is from NuxtJS Content Official Documentation.
export default async () => { const { $content } = require('@nuxt/content') const files = await $content({ deep: true }).only(['path']).fetch() return files.map((file) => (file.path === '/index' ? '/' : file.path)) }
Import createRoute.js
file at the top of the nuxt.config.js file
import createRoutes from "./utils/createRoutes" export default { // ... }
Add @nuxtjs/sitemap
to modules
export default { // ... modules: [ '@nuxt/content', '@nuxtjs/sitemap', ], // ... }
Configure sitemap
export default { // ... sitemap: { hostname: process.env.BASE_URL, gzip: true, routes() { return createRoutes(); } } // ... }