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: sitemap is empty with Content v3 #409

Closed
HADB opened this issue Jan 20, 2025 · 1 comment
Closed

fix: sitemap is empty with Content v3 #409

HADB opened this issue Jan 20, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@HADB
Copy link

HADB commented Jan 20, 2025

🐛 The bug

Hi!

I’m currently migrating my project to Nuxt Content v3, and I’ve encountered an issue with @nuxtjs/sitemap version 7.2.1.

The /__sitemap__/posts.xml and /__sitemap__/pages.xml in my project are empty.

After debugging, I found that /__sitemap__/nuxt-content-urls.json returns an empty array. Further logs revealed that the sitemap property in the result of queryCollection is null for every item. However, I’m not sure how to proceed with pinpointing the issue.

Below are my configs:

nuxt.config.ts

  sitemap: {
    sitemaps: {
      pages: {
        includeAppSources: true,
        exclude: [
          '/posts/**',
          '/tags/**',
          '/test',
        ],
      },
      posts: {
        includeAppSources: true,
        include: [
          '/posts/**',
        ],
      },
      tags: {
        sources: [
          '/api/__sitemap__/tags',
        ],
      },
    },
  },

content.config.ts

import { defineCollection, defineContentConfig, z } from '@nuxt/content'
import { asSitemapCollection } from '@nuxtjs/sitemap/content'

export default defineContentConfig({
  collections: {
    pages: defineCollection(
      asSitemapCollection({
        type: 'page',
        source: '*.md',
        schema: z.object({
          hideComments: z.boolean().optional(),
        }),
      }),
    ),
    posts: defineCollection(
      asSitemapCollection({
        type: 'page',
        source: 'posts/*.md',
        schema: z.object({
          class: z.string().optional(),
          cover: z.string().optional(),
          coverSize: z.object({ width: z.number(), height: z.number() }).optional(),
          date: z.string(),
          draft: z.boolean().optional(),
          hideComments: z.boolean().optional(),
          readingTime: z.object({}),
          tags: z.array(z.string()),
          time: z.string().optional(),
        }),
      }),
    ),
  },
})

🛠️ To reproduce

https://github.com/HADB/hadb.me/tree/feat/content-v3-migration

🌈 Expected behavior

ℹ️ Additional context

No response

@HADB HADB added the bug Something isn't working label Jan 20, 2025
@harlan-zw
Copy link
Collaborator

Hi, thanks for the issue. This looks like an issue with the Nuxt Content hooks running before the sitemap module loads. A work around for the time being is to load @nuxt/content last in your modules.

I'll push up a console warning for this use case but I'll need Nuxt Content to fix this upstream.

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