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

docs: add example of additional sorting options for queryContent #2042

Merged
merged 2 commits into from
Apr 28, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion docs/content/4.api/2.composables/1.query-content.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,19 @@ const articles = await queryContent('articles')

```

> `sort()`{lang="ts"} method does **case-sensitive** sort by default. There is some magical options you can pass to sort options to change sort behavior, like sorting **case-insensitive**.
> `sort()`{lang="ts"} method does **case-sensitive, alphabetical** sort by default. There is some magical options you can pass to sort options to change sort behavior, like sorting **case-insensitive** or **numerically rather than alphabetically**.
>
> - `$sensitivity`{lang=ts}: Change case sensitivity. Like using `$sensitivity: 'base'`{lang=ts} for case-insensitive sort
> - `$numeric`{lang=ts}: Boolean whether numeric collation should be used, such that `"1" < "2" < "10"`.
> - `$caseFirst`{lang=ts}: Whether upper case or lower case should sort first.

For example, to sort a list of people from youngest to oldest:
```ts
const people = await queryContent('people')
.sort({ age: 1, $numeric: 1 })
james-tyner marked this conversation as resolved.
Show resolved Hide resolved
.find()
```

These options are given to [Intl.Collator()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#parameters).

## `limit(count)`
Expand Down