atmosphere explorer pds.ls
tool typescript atproto

fix favicon fetch order

handle.invalid f84c03bb 21ae96cb

verified
+13 -5
+13 -5
src/worker.js
··· 505 505 if (pageRes.ok && (pageRes.headers.get("content-type") ?? "").includes("text/html")) { 506 506 let bestHref = null; 507 507 let bestPriority = -1; 508 + let bestSize = 0; 508 509 509 510 const rewriter = new HTMLRewriter().on("link", { 510 511 element(el) { ··· 513 514 const href = el.getAttribute("href"); 514 515 if (!href) return; 515 516 516 - // Prefer apple-touch-icon > icon with sizes > icon > shortcut icon 517 + // Prefer icon with sizes > icon > apple-touch-icon > shortcut icon 517 518 let priority = 0; 518 - if (rel === "apple-touch-icon") priority = 3; 519 - else if (rel === "icon" && el.getAttribute("sizes")) priority = 2; 520 - else if (rel === "icon") priority = 1; 519 + if (rel === "icon" && el.getAttribute("sizes")) priority = 3; 520 + else if (rel === "icon") priority = 2; 521 + else if (rel === "apple-touch-icon") priority = 1; 521 522 522 - if (priority > bestPriority) { 523 + const sizesAttr = el.getAttribute("sizes") ?? ""; 524 + const size = Math.max(...sizesAttr.split(/\s+/).map((s) => parseInt(s) || 0), 0); 525 + 526 + if ( 527 + priority > bestPriority || 528 + (priority === bestPriority && size > bestSize && size <= 64) 529 + ) { 523 530 bestPriority = priority; 531 + bestSize = size; 524 532 bestHref = href; 525 533 } 526 534 },