INNER CODE UNIT · JavaScript
safeHost
Manavarya09/design-extract · src/gallery/index.js:36
function safeHost(url) {
try { return new URL(url).hostname.replace(/^www\./, ''); } catch { return url; }
}
// Build the gallery model: dedupe slugs, sort best-first, compute stats.
export function buildGallery(reports = []) {
const seen = new Map();
const items = [];
for (const r of reports) {
const item = toGalleryItem(r);
// Disambiguate colliding slugs (two clones of the same host) deterministically.
if (seen.has(item.slug)) {
const n = seen.get(item.slug) + 1;
seen.set(item.slug, n);
item.slug = `${item.slug}-${n}`;
} else {
seen.set(item.slug, 1);
}