From 8ec935d2385d64711c0d8d383001a5d3371b723b Mon Sep 17 00:00:00 2001 From: Falkan Date: Wed, 18 Mar 2026 21:13:17 -0400 Subject: [PATCH] fix: alpha sort by labelPlural primary, symbol secondary Handles ties like 'Barrel (US fluid)' vs 'Barrel (US dry)' --- data/units.json | 29 +++++++++++++++++++---------- src/routes/+page.svelte | 5 ++++- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/data/units.json b/data/units.json index 8538ba8..f76b989 100644 --- a/data/units.json +++ b/data/units.json @@ -7,7 +7,7 @@ "symbol": "dl", "group": "dickloads", "toBase": 1, - "description": "See {pound:description}" + "description": "See {pound:description}. Let's also look at {us-oil-bbl}." }, { "id": "pound", @@ -19,10 +19,10 @@ "description": "My description is {dickload:description}" }, { - "id": "barrel", - "label": "barrel", - "labelPlural": "barrels", - "symbol": "bbl", + "id": "us-oil-bbl", + "label": "oil barrel (US)", + "labelPlural": "oil barrels (US)", + "symbol": "us oil bbl", "group": "dickloads", "toBase": 13.3192584, "description": "Weight is based on pure water at 4 degrees celsius.", @@ -106,26 +106,35 @@ }, { "id": "us-fluid-bbl", - "label": "US fluid barrel", - "labelPlural": "US fluid barrels", + "label": "barrel", + "labelPlural": "barrels", "symbol": "us fluid bbl", "group": "dickloads", "toBase": 9.9894438 }, { "id": "us-dry-bbl", - "label": "US dry barrel", - "labelPlural": "US dry barrels", + "label": "dry barrel", + "labelPlural": "dry barrels", "symbol": "us dry bbl", "group": "dickloads", "toBase": 1 + }, + { + "id": "us-hogshead", + "label": "hogshead (US)", + "labelPlural": "hogsheads (US)", + "symbol": "us hhd", + "group": "dickloads", + "toBase": 19.9788876, + "description": "Equal to two US fluid barrels." } ], "groups": [ { "id": "dickloads", "label": "Weights and Masses", - "baseUnitId": "", + "baseUnitId": "dickload", "toUniversal": 1, "sortOrder": "alpha", "hidden": false, diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 58de9fd..676e1cd 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -153,7 +153,10 @@ const items = byGroup.get(group.id); if (items?.length) { const sorted = group.sortOrder === 'alpha' - ? [...items].sort((a, b) => a.unit.label.localeCompare(b.unit.label)) + ? [...items].sort((a, b) => { + const labelCmp = a.unit.labelPlural.localeCompare(b.unit.labelPlural); + return labelCmp !== 0 ? labelCmp : a.unit.symbol.localeCompare(b.unit.symbol); + }) : items; sections.push({ groupLabel: group.label, alwaysShowLabel: group.alwaysShowLabel ?? false, items: sorted }); }