75 lines
3.3 KiB
JavaScript
75 lines
3.3 KiB
JavaScript
const WIDTH = 1200;
|
|
const HEIGHT = 630;
|
|
const FONT_STACK =
|
|
"-apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif";
|
|
|
|
/**
|
|
* @param {string} value
|
|
*/
|
|
function escapeXml(value) {
|
|
return String(value)
|
|
.replace(/&/g, "&")
|
|
.replace(/</g, "<")
|
|
.replace(/>/g, ">")
|
|
.replace(/"/g, """)
|
|
.replace(/'/g, "'");
|
|
}
|
|
|
|
/**
|
|
* Plain, flat, no-gradient stat tile: a big number over a small label.
|
|
*/
|
|
function statTile(x, y, w, h, value, label, accent) {
|
|
return `
|
|
<g>
|
|
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="14" fill="#15161a" stroke="#2a2b30" stroke-width="1"/>
|
|
<text x="${x + 28}" y="${y + h / 2 - 4}" font-family="${FONT_STACK}" font-size="52" font-weight="700" fill="${accent}">${escapeXml(value)}</text>
|
|
<text x="${x + 28}" y="${y + h - 22}" font-family="${FONT_STACK}" font-size="18" fill="#9a9ba3" letter-spacing="0.5">${escapeXml(label)}</text>
|
|
</g>`;
|
|
}
|
|
|
|
/**
|
|
* @param {object} params
|
|
* @param {string} params.repoLabel e.g. "owner/repo"
|
|
* @param {string} params.windowLabel e.g. "2026 Wrapped" or "Last 365 days"
|
|
* @param {ReturnType<typeof import("./stats.mjs").computeStats>} params.stats
|
|
* @param {string} [params.accent] hex color, default a single muted accent
|
|
* @returns {string} SVG markup
|
|
*/
|
|
export function renderCard({ repoLabel, windowLabel, stats, accent = "#4f8cff" }) {
|
|
const topContributor = stats.topContributors[0];
|
|
|
|
const languageLine = stats.topLanguages.length
|
|
? stats.topLanguages.map((l) => l.language).join(" · ")
|
|
: "no file data";
|
|
|
|
const tiles = [
|
|
statTile(60, 240, 260, 150, String(stats.totalCommits), "COMMITS", accent),
|
|
statTile(340, 240, 260, 150, String(stats.activeDays), "ACTIVE DAYS", accent),
|
|
statTile(620, 240, 260, 150, String(stats.longestStreak), "LONGEST STREAK (DAYS)", accent),
|
|
statTile(
|
|
900,
|
|
240,
|
|
240,
|
|
150,
|
|
stats.busiestWeekday ? stats.busiestWeekday.slice(0, 3).toUpperCase() : "—",
|
|
"BUSIEST DAY",
|
|
accent
|
|
),
|
|
].join("\n");
|
|
|
|
return `<svg xmlns="http://www.w3.org/2000/svg" width="${WIDTH}" height="${HEIGHT}" viewBox="0 0 ${WIDTH} ${HEIGHT}">
|
|
<rect width="${WIDTH}" height="${HEIGHT}" fill="#0a0a0c"/>
|
|
<text x="60" y="90" font-family="${FONT_STACK}" font-size="22" font-weight="600" fill="${accent}" letter-spacing="2">GIT WRAPPED</text>
|
|
<text x="60" y="160" font-family="${FONT_STACK}" font-size="54" font-weight="700" fill="#f4f4f5">${escapeXml(repoLabel)}</text>
|
|
<text x="60" y="200" font-family="${FONT_STACK}" font-size="22" fill="#9a9ba3">${escapeXml(windowLabel)}</text>
|
|
${tiles}
|
|
<text x="60" y="450" font-family="${FONT_STACK}" font-size="18" fill="#9a9ba3" letter-spacing="0.5">TOP LANGUAGES</text>
|
|
<text x="60" y="482" font-family="${FONT_STACK}" font-size="26" fill="#f4f4f5">${escapeXml(languageLine)}</text>
|
|
<text x="60" y="540" font-family="${FONT_STACK}" font-size="18" fill="#9a9ba3" letter-spacing="0.5">TOP CONTRIBUTOR</text>
|
|
<text x="60" y="572" font-family="${FONT_STACK}" font-size="26" fill="#f4f4f5">${escapeXml(
|
|
topContributor ? `${topContributor.name} (${topContributor.count} commits)` : "—"
|
|
)}</text>
|
|
<text x="${WIDTH - 60}" y="${HEIGHT - 30}" font-family="${FONT_STACK}" font-size="16" fill="#5a5b63" text-anchor="end">git-year-wrapped</text>
|
|
</svg>`;
|
|
}
|