nuxt / content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
https://content.nuxt.com
MIT License
3.13k stars 627 forks source link

Adding (date | custom) sorting #2383

Closed Ev357 closed 11 months ago

Ev357 commented 1 year ago

Is your feature request related to a problem? Please describe

I'm making a blog, and i'dlike to sort by posts by date. I have a date in each md post in this format: DD.MM.YYYY.

---
title: Hello World!
description: Nuxt is the best
date: 18.10.2023
---

# Hello World!

![image](/img/blog/image.jpg)

Certainly i could do that with the classic .sort(), but it would'not work with limit() and skip(). I did some search but i coud'nt find any way to do so with queryContent().

Describe the solution you'd like

I'd would be cool to have a custom sorting function, exactly like the .sort().

Describe alternatives you've considered

For now i think i'l do it the bad way, i'll get all the posts, sort them, and filter them with manually. I also found nuxt-content-git, but i don't like it that much, and i don't want to add too many dependencies to my project.

Additional context

if I'm doing something wrong, please correct me, i'm always trying to write code as clean as possible, so i'd be grateful for any tips.

Barbapapazes commented 1 year ago

Hello, have you try to provide a YML date (format YYYY-MM-DD)? Using the YML date format will return a date.

Ev357 commented 1 year ago

Hello, have you try to provide a YML date (format YYYY-MM-DD)? Using the YML date format will return a date.

Hello, thank you for your quick reply, you're a lifesaver. I hadn't thought of that. It does work :D

Ev357 commented 1 year ago

So ig, this issue can be closed right.

vorant94 commented 7 months ago

@Barbapapazes while the proposed solution works for case with dates what about making it more generic? For example allow users to provide custom 'compareWith' callback instead of mongo-like API or alongside with it?

I'm exploring Nuxt in general and Nuxt Content in particular and this feature sounds like something I can try to make a PR with...