Skip to content

Blog posts page: custom sorting logic #5692

@Josh-Cena

Description

@Josh-Cena

🚀 Feature

Let's be less opinionated and let users decide on the sorting logic.

Have you read the Contributing Guidelines on issues?

Yes

Has this been requested on Canny?

Requested on Discord

Motivation

Sorting by descending time works in almost all cases, but we shouldn't assume that all users use the blog for time-based information. E.g., sort by alphabetical order? Sort by tags?

API Design

A new comparePosts plugin option, which accepts a function that is passed to the sorting algorithm:

blogPosts.sort(
(a, b) => b.metadata.date.getTime() - a.metadata.date.getTime(),
);

And yes, it will receive the entire blog post, with all of its metadata and content.

Have you tried building it?

No; should be trivial

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureThis is not a bug or issue with Docusausus, per se. It is a feature request for the future.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions