Skip to content

[feature] Add collections filter #620

@Minhir

Description

@Minhir

Based on #566 discussion.

It would be nice to have an option to filter the collection during the build step:

const publicPosts = defineCollection({
    name: "posts",
    directory: "src/content/posts",
    include: "**/*.md",
    filter: ({level}) => level === "public"
});

const privatePosts = defineCollection({
    name: "posts",
    directory: "src/content/posts",
    include: "**/*.md",
    filter: ({level}) => level === "private"
});

or

const posts = defineCollection({
    name: "posts",
    directory: "src/content/posts",
    include: "**/*.md",
});

const publicPosts = posts.filter(({level}) => level === "public"); // here we can potentially have `.map` if derived collection has a bit different shape

I guess filter should be after transform step to be able to use complex conditions and features like other collections access.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions