mirror of
https://github.com/librespeed/speedtest.git
synced 2026-08-04 06:39:45 +00:00
fix: handle parenthetical qualifiers and multi-comma server names
Parse server names more robustly for sorting: - "City, Country, Provider" → use second part as country - "City, Country (1) (Hetzner)" → strip parentheticals from country - "Frankfurt, Germany (FRA01)" → country is "Germany" not "Germany (FRA01)"
This commit is contained in:
parent
42d700cf08
commit
69fa7a4edb
2 changed files with 44 additions and 19 deletions
|
|
@ -230,17 +230,30 @@ function populateDropdown(servers) {
|
|||
});
|
||||
}
|
||||
|
||||
// Sort servers by country, then by city within the same country
|
||||
// Sort servers by country, then by city within the same country.
|
||||
// Name formats: "City, Country", "City, Country (qualifier)", "City, Country, Provider", "Country"
|
||||
const parseServerName = (name) => {
|
||||
const parts = (name || "").split(",").map((s) => s.trim());
|
||||
let country, city;
|
||||
if (parts.length >= 3) {
|
||||
// "City, Country, Provider" — use second part as country
|
||||
country = parts[1];
|
||||
city = parts[0];
|
||||
} else if (parts.length === 2) {
|
||||
country = parts[1];
|
||||
city = parts[0];
|
||||
} else {
|
||||
country = parts[0];
|
||||
city = "";
|
||||
}
|
||||
// Strip parenthetical qualifiers for sorting: "Germany (1) (Hetzner)" → "Germany"
|
||||
country = country.replace(/\s*\([^)]*\)\s*/g, "").trim();
|
||||
return { country, city };
|
||||
};
|
||||
const sorted = [...servers].sort((a, b) => {
|
||||
const nameA = a.name || "";
|
||||
const nameB = b.name || "";
|
||||
const commaA = nameA.lastIndexOf(",");
|
||||
const commaB = nameB.lastIndexOf(",");
|
||||
const countryA = commaA >= 0 ? nameA.substring(commaA + 1).trim() : nameA;
|
||||
const countryB = commaB >= 0 ? nameB.substring(commaB + 1).trim() : nameB;
|
||||
const cityA = commaA >= 0 ? nameA.substring(0, commaA).trim() : "";
|
||||
const cityB = commaB >= 0 ? nameB.substring(0, commaB).trim() : "";
|
||||
return countryA.localeCompare(countryB) || cityA.localeCompare(cityB);
|
||||
const pa = parseServerName(a.name);
|
||||
const pb = parseServerName(b.name);
|
||||
return pa.country.localeCompare(pb.country) || pa.city.localeCompare(pb.city);
|
||||
});
|
||||
|
||||
// Populate the list to choose from
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue