Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

managing sitemap at runtime in swr with data from an headless cms #59

Closed
Sandros94 opened this issue May 24, 2023 · 10 comments
Closed

managing sitemap at runtime in swr with data from an headless cms #59

Sandros94 opened this issue May 24, 2023 · 10 comments

Comments

@Sandros94
Copy link

Details

So, as stated in the nuxt-seo-kit I've noticed that simple-sitemap needs to prerender all the pages so that it could create the sitemap. Quite fine for SSG but not so much when on SSR with SWR and ISR...

So I started studying how dynamic urls setup works, but if I understand it correctly, for the loc I should provide the slug and not the full url right? But then where I put the full url? In the sitemap.siteUrl inside nuxt.config.ts? But if I do so doesn't it reactivate the prerendering?

@harlan-zw
Copy link
Collaborator

Hey @Sandros94, in the latest version of nuxt-simple-sitemp it reads from the request headers to determine the site URL. You should be able to just leave siteUrl undefined if you're generating the sitemap at runtime.

@Sandros94
Copy link
Author

Sandros94 commented May 25, 2023

Thanks, as soon as I manage to list the slugs from my backend and test this I'll update.

UPDATE: I'm in the process of studying different CMSs (testing payload rn) so I might take at least a week before I get back to this. 🙁

@arjunhadke7
Copy link

Hey @Sandros94, in the latest version of nuxt-simple-sitemp it reads from the request headers to determine the site URL. You should be able to just leave siteUrl undefined if you're generating the sitemap at runtime.

Hi, I added some slugs statically for now (to check if they are added to the sitemap, before fetching them from my CMS) to the code and my code looks like this:

export default cachedEventHandler(async () => {
    // const [
    //   posts,
    // ] = await Promise.all([
    //   {
    //     url:'/blog/hello-world',
    //     updatedAt:'8998',
    //   }
    // ])
    // return [posts].map((p) => {
    //   return { loc: p.url, lastmod: p.updatedAt }
    // })
    return [
        {
            loc: 'hello-there', lastMod: '8378787'
        },
        {
            loc: 'hello-world', lastMod: '8378787'
        },
    ]
  }
  , {
    name: 'sitemap-dynamic-urls',
    maxAge: 60 * 10 // cache URLs for 10 minutes
  }
  )

I generated a build and I cant see the list of those in the sitemap.xml file. Only the prerendered routes are available.

What must be going wrong? I am new to Nuxt in general.

@harlan-zw
Copy link
Collaborator

@arjunhadke7 Does it work in dev? If so, what method are you using to build / preview?

@arjunhadke7
Copy link

@arjunhadke7 Does it work in dev? If so, what method are you using to build / preview?

No it doesnt show up at all on dev.

@arjunhadke7
Copy link

@harlan-zw For now I am relying on Start-time dynamic URLs.
This section: https://github.com/harlan-zw/nuxt-simple-sitemap#start-time-dynamic-urls

Since I dont have a lot many posts or pages that are being called from the CMS.

@harlan-zw
Copy link
Collaborator

Will track this as part of #80

@harlan-zw harlan-zw closed this as not planned Won't fix, can't repro, duplicate, stale Jul 6, 2023
@Sandros94
Copy link
Author

Will track this as part of #80

Sounds good.
Currently I'm still scratching my head around how should I handle this in the backend (not to mention a small bug in the directus flow). But we do agree that it is best suited there, since the data handled by the backend and nuxt only creates the interactivity.

@notflip
Copy link

notflip commented Sep 4, 2023

@Sandros94 I'm also struggling with Directus and this repository, did you find a solution?

@Sandros94
Copy link
Author

@Sandros94 I'm also struggling with Directus and this repository, did you find a solution?

Not really, I got offtrack when the new SDK released.

Currently I'm testing stuff around the nuxt-directus module and the new SDK. Only then I would have come back to this topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants