Repository navigation
Expand file tree
/
Copy pathrenderStatsCard.js
More file actions
97 lines (88 loc) · 2.6 KB
/
Copy pathrenderStatsCard.js
File metadata and controls
97 lines (88 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const { kFormatter } = require("../src/utils");
const createTextNode = ({ icon, label, value, lineHeight, id }) => {
const classname = icon === "★" && "star-icon";
const kValue = kFormatter(value);
return `
<tspan x="25" dy="${lineHeight}" class="stat bold">
<tspan data-testid="icon" class="icon ${classname}" fill="#4C71F2">${icon}</tspan> ${label}:</tspan>
<tspan data-testid="${id}" x="155" dy="0" class="stat">${kValue}</tspan>
`;
};
const renderStatsCard = (stats = {}, options = { hide: [] }) => {
const {
name,
totalStars,
totalCommits,
totalIssues,
totalPRs,
contributedTo,
} = stats;
const {
hide = [],
show_icons = false,
hide_border = false,
line_height = 25,
} = options;
const lheight = parseInt(line_height);
const STAT_MAP = {
stars: createTextNode({
icon: "★",
label: "Total Stars",
value: totalStars,
lineHeight: lheight,
id: "stars",
}),
commits: createTextNode({
icon: "🕗",
label: "Total Commits",
value: totalCommits,
lineHeight: lheight,
id: "commits",
}),
prs: createTextNode({
icon: "🔀",
label: "Total PRs",
value: totalPRs,
lineHeight: lheight,
id: "prs",
}),
issues: createTextNode({
icon: "ⓘ",
label: "Total Issues",
value: totalIssues,
lineHeight: lheight,
id: "issues",
}),
contribs: createTextNode({
icon: "📕",
label: "Contributed to",
value: contributedTo,
lineHeight: lheight,
id: "contribs",
}),
};
const statItems = Object.keys(STAT_MAP)
.filter((key) => !hide.includes(key))
.map((key) => STAT_MAP[key]);
const height = 45 + (statItems.length + 1) * lheight;
const border = `<rect data-testid="card-border" x="0.5" y="0.5" width="494" height="99%" rx="4.5" fill="#FFFEFE" stroke="#E4E2E2"/>`;
return `
<svg width="495" height="${height}" viewBox="0 0 495 ${height}" fill="none" xmlns="http://www.w3.org/2000/svg">
<style>
.header { font: 600 18px 'Segoe UI', Ubuntu, Sans-Serif; fill: #2F80ED }
.stat { font: 600 14px 'Segoe UI', Ubuntu, Sans-Serif; fill: #333 }
.star-icon { font: 600 18px 'Segoe UI', Ubuntu, Sans-Serif; }
.bold { font-weight: 700 }
.icon {
display: ${!!show_icons ? "block" : "none"};
}
</style>
${hide_border ? "" : border}
<text x="25" y="35" class="header">${name}'s GitHub Stats</text>
<text y="45">
${statItems.toString().replace(/\,/gm, "")}
</text>
</svg>
`;
};
module.exports = renderStatsCard;