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

fix: cant add more than one route in sitemap:resolved nitro hook #396

Closed
felipebat20 opened this issue Jan 14, 2025 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@felipebat20
Copy link

🐛 The bug

export default defineNitroPlugin((nitroApp) => {
  nitroApp.hooks.hook('sitemap:resolved', async (ctx) => {
    ctx.urls.push({
      loc: '/test-1'
    });

    ctx.urls.push({
      loc: '/test-2'
    });
  });
});

In this example, test-1 will appears in sitemap. But, test-2 does not appear.

🛠️ To reproduce

https://nuxtseo.com/docs/sitemap/nitro-api/nitro-hooks

🌈 Expected behavior

Possibly add more than one route in sitemap by the hook sitemap:resolved.

ℹ️ Additional context

No response

@felipebat20 felipebat20 added the bug Something isn't working label Jan 14, 2025
@felipebat20 felipebat20 changed the title Cant add more than one route in sitemap:resolved nitro hook fix: cant add more than one route in sitemap:resolved nitro hook Jan 14, 2025
@felipebat20
Copy link
Author

updating. if i do in this format below. It'll work:

export default defineNitroPlugin((nitroApp) => {
  nitroApp.hooks.hook('sitemap:resolved', async (ctx) => {
    ctx.urls.push({
          loc: '/test-1',
          _abs: false,
          _path: { pathname: '/test-1', search: '', hash: '' },
          _relativeLoc: '/test-1',
          _key: new URL('/test-1', process.env.NUXT_SITE_URL).href
    });

    ctx.urls.push({
          loc: '/test-2',
          _abs: false,
          _path: { pathname: '/test-2', search: '', hash: '' },
          _relativeLoc: '/test-2',
          _key: new URL('/test-2', process.env.NUXT_SITE_URL).href
    });
  });
});

@harlan-zw
Copy link
Collaborator

harlan-zw commented Jan 15, 2025

Thanks for the issue, this raises a good point. I've added a new hook to solve this properly, please see #397

It will be available in v7.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants