Skip to content

Conversation

@harlan-zw
Copy link
Collaborator

@harlan-zw harlan-zw commented Dec 4, 2025

πŸ”— Linked issue

#501

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Adds a filter option to asSitemapCollection() for Nuxt Content v3, allowing users to exclude content entries from the sitemap at runtime.

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

export default defineContentConfig({
  collections: {
    // The `name` option must match the collection key β€” here both are 'blog'
    blog: defineCollection(
      asSitemapCollection({
        type: 'page',
        source: 'blog/**/*.md',
        schema: z.object({
          date: z.string().optional(),
          draft: z.boolean().optional(),
        }),
      }, {
        name: 'blog', // ← must match the key above
        filter: (entry) => {
          // exclude drafts and future-dated posts
          if (entry.draft) return false
          if (entry.date && new Date(entry.date) > new Date()) return false
          return true
        },
      }),
    ),
  },
})

Important: The name option must match the collection key exactly. This is how the filter is matched to the correct collection at runtime.

How it works:

  • Filter functions are stored in a global Map at build time via asSitemapCollection()
  • Serialized into a virtual Nitro module (#sitemap/content-filters) during nitro:config
  • Applied at query time in the content URL handler, fetching all fields when a filter is present

Changes:

  • src/content.ts β€” AsSitemapCollectionOptions interface with name and filter, global filter storage
  • src/module.ts β€” virtual module injection for filters
  • nuxt-content-urls-v3.ts β€” conditional field selection and filter application
  • Docs and e2e tests with draft/future/published fixtures

harlan-zw and others added 3 commits January 28, 2026 13:35
- Add draft.md, future.md, published.md fixture files
- Consolidate filtering test into single assertion
- Update default test snapshot with published entry
- Remove unused _collectionFilters export

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@harlan-zw harlan-zw force-pushed the feat/content-filters branch from ff31ff1 to c8f29cb Compare January 28, 2026 02:47
@harlan-zw harlan-zw changed the title feat: content filters WIP feat: content collection filters Jan 28, 2026
@harlan-zw harlan-zw changed the title feat: content collection filters feat(content): collection filters Jan 28, 2026
@harlan-zw harlan-zw marked this pull request as ready for review January 28, 2026 02:49
harlan-zw and others added 6 commits January 28, 2026 13:51
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…hema & TEntry

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@harlan-zw harlan-zw merged commit ae9cc3b into main Jan 28, 2026
4 checks passed
@harlan-zw harlan-zw deleted the feat/content-filters branch January 28, 2026 04:25
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

Successfully merging this pull request may close these issues.

2 participants