nuxt / nuxt/content

queryCollection by path prefix

Open
#3,798 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
3.7k
Forks
746
Avg merge
1d 16h
Merged PRs (30d)
3

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the queryCollection().path() API described in the issue and inspect its existing exact-path behavior. Add coverage for trailing-slash directory prefixes and non-trailing-slash file or index lookups, then run the relevant query-collection tests to confirm both forms work.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxt, typescript
Domain
api, content
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.