Commit 9523f3a8 authored by Vincent's avatar Vincent

Prefer readable URLS on HTTPS

parent cec2088c
Pipeline #37671230 passed with stage
in 2 minutes and 34 seconds
......@@ -149,5 +149,31 @@ async function getUrls() {
const urls = data.results.bindings.map(result => result.urls.value);
return urls;
}
\ No newline at end of file
return urls.sort(compareUrls);
}
function compareUrls(url1, url2) {
// URL beginning with `https://`, and ending in a non-digit character (of the TLD) and a potential trailing slash
const httpsDomainRE = /^https:\/\/(.*)\D\/?$/;
// URL beginning with `http://`, and ending in a non-digit character (of the TLD) and a potential trailing slash
const httpDomainRE = /^http:\/\/(.*)\D\/?$/;
// Regular URL's pointing to an HTTPS address come first
if (httpsDomainRE.test(url1)) {
return -1;
} else if(httpsDomainRE.test(url2)) {
return 1;
// IP addresses using HTTPS come second
} else if(url1.substr(0, 5) === 'https') {
return -1;
} else if(url2.substr(0, 5) === 'https') {
return 1;
// Only then come regular domains hosted through naked HTTP
} else if(httpDomainRE.test(url1)) {
return -1;
} else if(httpDomainRE.test(url2)) {
return 1;
}
// And if both are an IP address through naked HTTP, we don't care which comes first:
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment