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

v3: wrong sorting on queryCollectionNavigation() #3087

Open
Onouriis opened this issue Feb 4, 2025 · 2 comments
Open

v3: wrong sorting on queryCollectionNavigation() #3087

Onouriis opened this issue Feb 4, 2025 · 2 comments

Comments

@Onouriis
Copy link

Onouriis commented Feb 4, 2025

Environment

  • Operating System: Darwin
  • Node Version: v23.7.0
  • Nuxt Version: 3.15.4
  • CLI Version: 3.21.1
  • Nitro Version: 2.10.4
  • Package Manager: [email protected]

Version

v3

Reproduction

https://content.nuxt.com/docs/collections/types#ordering-files

Description

Hello,

I think there is a bug when ordering large navigation when using numeric prefix.

For example, my files are:

1.navigation_1.md
2.navigation_2.md
3.navigation_3.md
....
10.navigation_10.md
11.navigation_11.md
12.navigation_12.md

should return exactly this ordering.
However, I get:

1.navigation_1.md
10.navigation_10.md
11.navigation_11.md
12.navigation_12.md
2.navigation_2.md
3.navigation_3.md

It seems like it's not parsing as Integer the file prefix.

@funkel1989
Copy link

I am also seeing this issue

@nexoscreator
Copy link
Contributor

It looks like the file ordering is being treated as lexicographical (string-based) sorting rather than numeric sorting. This means that "10" comes before "2" because "1" is smaller than "2" in string comparison.

Use Zero Padding (Recommended)

To force correct numeric sorting, pad single-digit numbers with leading zeros:

01.navigation_1.md
02.navigation_2.md
03.navigation_3.md
...
10.navigation_10.md
11.navigation_11.md
12.navigation_12.md

This ensures correct order because "01" comes before "02", "02" before "10", and so on.

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

No branches or pull requests

3 participants