Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions site/src/components/Leaderboard.astro
Original file line number Diff line number Diff line change
@@ -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[];
Expand Down Expand Up @@ -71,6 +71,7 @@ const split = (repo: string) => {
<p class="count" id="count" aria-live="polite">{entries.length} {entries.length === 1 ? "repo" : "repos"}</p>
</div>

<Fragment set:html={iconDef("thumbsup")} />
<div class="table" id="panel" role="tabpanel" aria-labelledby="tab-top">
{
entries.length === 0 ? (
Expand Down Expand Up @@ -182,12 +183,12 @@ const split = (repo: string) => {
<td class="act">
{e.discussion_url ? (
<a class="like" href={e.discussion_url} aria-label={`Like ${e.repo} on GitHub`}>
<Fragment set:html={icon("thumbsup")} />
<Fragment set:html={iconUse("thumbsup")} />
<span class="t">Like</span>
</a>
) : (
<span class="like" aria-disabled="true">
<Fragment set:html={icon("thumbsup")} />
<Fragment set:html={iconUse("thumbsup")} />
<span class="t">Likes open soon</span>
</span>
)}
Expand Down
9 changes: 9 additions & 0 deletions site/src/lib/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
`<svg hidden><symbol id="i-${name}" viewBox="0 0 ${octicons[name].heights[16].width} 16">${octicons[name].heights[16].path}</symbol></svg>`;

export const iconUse = (name: keyof typeof octicons, cls = "") => {
const w = octicons[name].heights[16].width;
return `<svg width="${w}" height="16" viewBox="0 0 ${w} 16" class="octicon octicon-${name} ${`oc ${cls}`.trim()}" aria-hidden="true"><use href="#i-${name}"></use></svg>`;
};

export const num = (n: number) => n.toLocaleString("en-US");

export const compact = (n: number) =>
Expand Down
Loading