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

Categories sort #32

Open
jt196 opened this issue Mar 6, 2023 · 1 comment
Open

Categories sort #32

jt196 opened this issue Mar 6, 2023 · 1 comment

Comments

@jt196
Copy link

jt196 commented Mar 6, 2023

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
Copy link

ZachSaucier commented Oct 21, 2023

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;
});

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

2 participants