Generate sitemap according prismic data in Nuxt

Hello there :v:
I'm guessing some of you have some experience with generating Sitemap for your project.
I'm having a Nuxt ( SSR full static ) project.
I'm using @nuxtjs/prismic
and @nuxtjs/sitemap module.

The sitemap module does not generate dynamic pages therefor we need to asynchronously retrieve all the pages we have on the website and process the data into a format required by the sitemap module.

I'm guessing that I need to write some build module where I would have access to prismic and then generate and write the desired data format.

Help me please to understand how to import or access prismic from module level so I can write the desired logic.

What are you using for deployment?

If you are using Netlify, the easiest way is to just use the Netlify Sitemap Plugin.

Best
Aleks

In nuxt.config.js add:

const Prismic = require("@prismicio/client");

And in sitemap configuration block:

sitemaps: [
      {
        path: "/sitemap-pages.xml",
        routes: async () => {
          const pages = await getData("page");
          return [...pages.map((i) => `/${i.uid}`)];
        },
      },
    ],

In your case names maybe different, but I hope you've got the idea :slight_smile:

2 Likes

I did as you suggest in your code and it works partially.
All of my static pages are probably rewritten and are missing data, however dynamic pages are filled correctly. Here how my sitemap looks

@martingjorceski, did you know that you can create the route for your Nuxt project using a Route Resolver?

With @nuxtjs/prismic you can add a routes option in the prismic.apiOptions configuration object and pass a similar object as you are doing with the other plugin.