Skip to content

queryCollection by path prefix #3798

Description

@ProgramRipper

Is your feature request related to a problem? Please describe

We usually place relevant file in different directory:

  • getting-started/
    • index.md
    • introduction.md
    • installation.md
    • ...

Sometime we may want to query all page under a directory, but

const { data } = await useAsyncData("/getting-started/", () =>
  queryCollection("content").path("/getting-started/").all(),
);

won't work, as `.path()" is exact match, not prefix match.

Describe the solution you'd like

const { data } = await useAsyncData("/getting-started/", () =>
  queryCollection("content").path("/getting-started/").all(),
);
  • With trailing slash (/getting-started/) means query all page under directory
  • Without trailing slash (/getting-started) means query a file (getting-started.md) or an index file (getting-started/index.md).

Describe alternatives you've considered

.where("path", "LIKE", "/getting-started/%")

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions