From e458007eacb0833f656901be4613bb66bc0d2a2a Mon Sep 17 00:00:00 2001 From: jamesconwaydev <148910373+jamesconwaydev@users.noreply.github.com> Date: Wed, 18 Nov 2026 08:25:48 -0700 Subject: [PATCH] perf(site): draw the row Like icon from one shared symbol Every leaderboard row inlined the full thumbsup path, 455 copies on the home page. The icon is now defined once per list and each row points at it with , taking index.html from 784 KB to 512 KB. --- site/src/components/Leaderboard.astro | 7 ++++--- site/src/lib/format.ts | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/site/src/components/Leaderboard.astro b/site/src/components/Leaderboard.astro index 7275154..0273c4d 100644 --- a/site/src/components/Leaderboard.astro +++ b/site/src/components/Leaderboard.astro @@ -1,7 +1,7 @@ --- import type { Category, SiteEntry } from "../lib/data.ts"; import { isFlagged, languages, trending } from "../lib/data.ts"; -import { ago, compact, icon, num, pct } from "../lib/format.ts"; +import { ago, compact, icon, iconDef, iconUse, num, pct } from "../lib/format.ts"; interface Props { entries: SiteEntry[]; @@ -71,6 +71,7 @@ const split = (repo: string) => {

{entries.length} {entries.length === 1 ? "repo" : "repos"}

+
{ entries.length === 0 ? ( @@ -182,12 +183,12 @@ const split = (repo: string) => { {e.discussion_url ? ( ) : ( )} diff --git a/site/src/lib/format.ts b/site/src/lib/format.ts index 2c42061..c0e12af 100644 --- a/site/src/lib/format.ts +++ b/site/src/lib/format.ts @@ -3,6 +3,15 @@ import octicons from "@primer/octicons"; export const icon = (name: keyof typeof octicons, cls = "") => octicons[name].toSVG({ "aria-hidden": "true", class: `oc ${cls}`.trim() }); +// A per-row icon is defined once with iconDef and drawn with iconUse, so 455 rows don't carry 455 copies of its path. +export const iconDef = (name: keyof typeof octicons) => + ``; + +export const iconUse = (name: keyof typeof octicons, cls = "") => { + const w = octicons[name].heights[16].width; + return ``; +}; + export const num = (n: number) => n.toLocaleString("en-US"); export const compact = (n: number) =>