josh-collinsworth / sveltekit-blog-starter

A preconfigured SvelteKit static blog starter, with Sass, Markdown, MDSvex, Rehype, background preloading, and more. See the README for full details.
https://sveltekit-static-starter.netlify.app/
MIT License
419 stars 81 forks source link

Categories sort #32

Open jt196 opened 1 year ago

jt196 commented 1 year ago

Hey dude, so, been using your template to learn a bit of Sveltekit, thanks for all the work.

You'll notice the blog/category categories isn't correctly alphabetically sorted, here's the code I used to fix it:

    const sortedUniqueCategories = Object.values(uniqueCategories).sort((a, b) => {
        return a.title.localeCompare(b.title);
    });
ZachSaucier commented 1 year ago

The above approach sorts by category name irrelevant of count.

To sort by count first and alphabetically within, you can use this:

const sortedUniqueCategories = Object.values(uniqueCategories).sort((a, b) => {
    return a.count === b.count ? a.title.localeCompare(b.title) : a.count > b.count;
});