β¨ Dynamic Sitemap with SSR without pre-render
Hello Discord,
I'm currently using the simple-sitemap module to handle my sitemap.
Since the site I'm building should be SSR without pre-rendering, I cant rely on the module to crawl my routes. So I want to query our CMS using the graphql-client module. I've tried the "sitemap:generate" hook and failed because it wouldn't import the generated GQL Query call.
I'm now wondering what is the best way to implement this for my context?
I kinda wanna make it work with simple-sitemap, but I'm almost ready to try just creating a sitemap.xml.ts in my server directory π
19 Replies
Unknown Userβ’2y ago
Message Not Public
Sign In & Join Server To View
Hmm I see. First of all thank you for the fast response.
Its seems to me the behavior of simple-sitemap and @funken-studio/sitemap-nuxt-3 is quite similar.
I think my biggest problem is the limitation of not being able to use imports inside the nuxt.config.ts.
That's why it never found my gql calls and that's also why my config never quite worked out. The funken-studio approach with a server api route that resolves the gql/api call actually seems genius.
Ill give it a shot and try my best with simple-sitemap, but I'll keep the package you recommended in mind.
Unknown Userβ’2y ago
Message Not Public
Sign In & Join Server To View
simple-sitemap is definitely suited towards prerendered apps but happy to get this working for you if you make an issue
there might be a way to run your server and crawl for URLs outside of a prerender
simple-sitemap aims to be minimal config
Wow, thanks for the feedback. I'm currently trying a couple of solutions. I'll get back to you / the github issues π
Unknown Userβ’2y ago
Message Not Public
Sign In & Join Server To View
not too sure about the specifics of that module sorry
Where is his example where you can import? For instance importing supabase module
I've created a server endpoint providing the data and then I used fetch in the arrow function that provides the routes
in my api-route file I can now use composable imports as usual (Gql Example:)
I'm sure you could do this using useFetch. I'm not sure why I didn't
https://github.com/harlan-zw/nuxt-simple-sitemap v2 may be useful if you're stuck with the other module
GitHub
GitHub - harlan-zw/nuxt-simple-sitemap: The simplest way to add XML...
The simplest way to add XML Sitemaps to your Nuxt 3 site. - GitHub - harlan-zw/nuxt-simple-sitemap: The simplest way to add XML Sitemaps to your Nuxt 3 site.
Just browsed through the change logs. Looks amazing! Thanks for the continued development. I'll migrate as soon as I get the chance to π
Unknown Userβ’2y ago
Message Not Public
Sign In & Join Server To View
Hey, the issue is that you're trying to use a nuxt app level composable in your nuxt config. This is why it's recommended to use an api endpoint for dynamic routes
although you may still have the same issue if the sanity module doesn't expose the composable for the server
Unknown Userβ’2y ago
Message Not Public
Sign In & Join Server To View
Hm well if you're doing the URLs through nuxt config they won't be dynamic. In which case you should just prerender all pages and it should discover your sitemap entries automatically
You'd just need to redeploy on content updates
But I'm also sure there's an easy way to use the sanity API via the server routes
Unknown Userβ’2y ago
Message Not Public
Sign In & Join Server To View
Nuxt generate
Should do it
With the crawler enabled, which I think it is by default
You can test locally
Unknown Userβ’2y ago
Message Not Public
Sign In & Join Server To View
Can't you use their pagination?