forked from mirrored/github-readme-stats
Compare commits
70
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5ba3238ab | ||
|
|
f4e731ee09 | ||
|
|
6f07b51c00 | ||
|
|
6e0522cdd9 | ||
|
|
4ce744f7b5 | ||
|
|
3565f25c46 | ||
|
|
a5114d12d0 | ||
|
|
20914797b0 | ||
|
|
11cb8dffc1 | ||
|
|
a885425b52 | ||
|
|
017e3ba180 | ||
|
|
03465922b0 | ||
|
|
9829ab990d | ||
|
|
6243c702c3 | ||
|
|
97cef21e4e | ||
|
|
55a3cecd49 | ||
|
|
e245941e5a | ||
|
|
04ed2bdd3f | ||
|
|
c33f3f617a | ||
|
|
589badc483 | ||
|
|
05b611ad58 | ||
|
|
bf0a15f94f | ||
|
|
b8425d36c8 | ||
|
|
866e509d07 | ||
|
|
c1e2858330 | ||
|
|
01f726c316 | ||
|
|
2770161e33 | ||
|
|
b320054e90 | ||
|
|
5675ce77b1 | ||
|
|
27029cd565 | ||
|
|
df42981d34 | ||
|
|
4ecebbca94 | ||
|
|
80e6d0acc5 | ||
|
|
0adcb158f9 | ||
|
|
2cb4861b24 | ||
|
|
3cebd8907b | ||
|
|
42503cf90c | ||
|
|
2466713261 | ||
|
|
9c08efedbf | ||
|
|
af36d0b2e1 | ||
|
|
1689ca6feb | ||
|
|
642d63d4f0 | ||
|
|
2a1d255e45 | ||
|
|
114225e72e | ||
|
|
cc558e4d7c | ||
|
|
6738c6db5f | ||
|
|
ede2574b13 | ||
|
|
c6ca64551e | ||
|
|
5448a611ba | ||
|
|
22aa6887f9 | ||
|
|
ffd927af6d | ||
|
|
f02186908d | ||
|
|
8f63eaeef9 | ||
|
|
70b0d025f8 | ||
|
|
dc95c44c22 | ||
|
|
adbc7a36c9 | ||
|
|
1651db55ec | ||
|
|
e40f214a76 | ||
|
|
88aa6fe30c | ||
|
|
ad731cdfcb | ||
|
|
237942c234 | ||
|
|
d505580a4f | ||
|
|
4dbab9a2a3 | ||
|
|
d8af18e465 | ||
|
|
1af63921b5 | ||
|
|
9ff83e0855 | ||
|
|
6349ec8f32 | ||
|
|
31f2920c09 | ||
|
|
19cf691983 | ||
|
|
36e838da62 |
+51
-35
@@ -87,16 +87,6 @@ const iconWithLabel = (icon, label, testid) => {
|
|||||||
* @returns {string} Repository card SVG object.
|
* @returns {string} Repository card SVG object.
|
||||||
*/
|
*/
|
||||||
const renderRepoCard = (repo, options = {}) => {
|
const renderRepoCard = (repo, options = {}) => {
|
||||||
const {
|
|
||||||
name,
|
|
||||||
nameWithOwner,
|
|
||||||
description,
|
|
||||||
primaryLanguage,
|
|
||||||
isArchived,
|
|
||||||
isTemplate,
|
|
||||||
starCount,
|
|
||||||
forkCount,
|
|
||||||
} = repo;
|
|
||||||
const {
|
const {
|
||||||
hide_border = false,
|
hide_border = false,
|
||||||
title_color,
|
title_color,
|
||||||
@@ -109,6 +99,42 @@ const renderRepoCard = (repo, options = {}) => {
|
|||||||
border_color,
|
border_color,
|
||||||
locale,
|
locale,
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
|
const i18n = new I18n({
|
||||||
|
locale,
|
||||||
|
translations: repoCardLocales,
|
||||||
|
});
|
||||||
|
|
||||||
|
const colors = getCardColors({
|
||||||
|
title_color,
|
||||||
|
icon_color,
|
||||||
|
text_color,
|
||||||
|
bg_color,
|
||||||
|
border_color,
|
||||||
|
theme,
|
||||||
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
name,
|
||||||
|
nameWithOwner,
|
||||||
|
description,
|
||||||
|
primaryLanguage,
|
||||||
|
isArchived,
|
||||||
|
isTemplate,
|
||||||
|
starCount,
|
||||||
|
forkCount,
|
||||||
|
} = repo;
|
||||||
|
|
||||||
|
const highlight = repo.highlight
|
||||||
|
? // @ts-ignore
|
||||||
|
getBadgeSVG(repo.highlight, colors.textColor)
|
||||||
|
: isTemplate
|
||||||
|
? // @ts-ignore
|
||||||
|
getBadgeSVG(i18n.t("repocard.template"), colors.textColor)
|
||||||
|
: isArchived
|
||||||
|
? // @ts-ignore
|
||||||
|
getBadgeSVG(i18n.t("repocard.archived"), colors.textColor)
|
||||||
|
: ""
|
||||||
|
|
||||||
const lineHeight = 10;
|
const lineHeight = 10;
|
||||||
const header = show_owner ? nameWithOwner : name;
|
const header = show_owner ? nameWithOwner : name;
|
||||||
@@ -125,27 +151,25 @@ const renderRepoCard = (repo, options = {}) => {
|
|||||||
const height =
|
const height =
|
||||||
(descriptionLines > 1 ? 120 : 110) + descriptionLines * lineHeight;
|
(descriptionLines > 1 ? 120 : 110) + descriptionLines * lineHeight;
|
||||||
|
|
||||||
const i18n = new I18n({
|
|
||||||
locale,
|
|
||||||
translations: repoCardLocales,
|
|
||||||
});
|
|
||||||
|
|
||||||
// returns theme based colors with proper overrides and defaults
|
// returns theme based colors with proper overrides and defaults
|
||||||
const colors = getCardColors({
|
|
||||||
title_color,
|
|
||||||
icon_color,
|
|
||||||
text_color,
|
|
||||||
bg_color,
|
|
||||||
border_color,
|
|
||||||
theme,
|
|
||||||
});
|
|
||||||
|
|
||||||
const svgLanguage = primaryLanguage
|
const svgLanguage = primaryLanguage
|
||||||
? createLanguageNode(langName, langColor)
|
? createLanguageNode(langName, langColor)
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
const totalStars = kFormatter(starCount);
|
let totalStars
|
||||||
const totalForks = kFormatter(forkCount);
|
let totalForks
|
||||||
|
if (isNaN(starCount)) {
|
||||||
|
totalStars = starCount;
|
||||||
|
} else {
|
||||||
|
totalStars = kFormatter(starCount);
|
||||||
|
}
|
||||||
|
if (isNaN(forkCount)) {
|
||||||
|
totalForks = forkCount;
|
||||||
|
} else {
|
||||||
|
totalForks = kFormatter(forkCount);
|
||||||
|
}
|
||||||
|
|
||||||
const svgStars = iconWithLabel(icons.star, totalStars, "stargazers");
|
const svgStars = iconWithLabel(icons.star, totalStars, "stargazers");
|
||||||
const svgForks = iconWithLabel(icons.fork, totalForks, "forkcount");
|
const svgForks = iconWithLabel(icons.fork, totalForks, "forkcount");
|
||||||
|
|
||||||
@@ -180,15 +204,7 @@ const renderRepoCard = (repo, options = {}) => {
|
|||||||
`);
|
`);
|
||||||
|
|
||||||
return card.render(`
|
return card.render(`
|
||||||
${
|
${highlight}
|
||||||
isTemplate
|
|
||||||
? // @ts-ignore
|
|
||||||
getBadgeSVG(i18n.t("repocard.template"), colors.textColor)
|
|
||||||
: isArchived
|
|
||||||
? // @ts-ignore
|
|
||||||
getBadgeSVG(i18n.t("repocard.archived"), colors.textColor)
|
|
||||||
: ""
|
|
||||||
}
|
|
||||||
|
|
||||||
<text class="description" x="25" y="-5">
|
<text class="description" x="25" y="-5">
|
||||||
${descriptionSvg}
|
${descriptionSvg}
|
||||||
|
|||||||
+44
-32
@@ -40,7 +40,12 @@ const createTextNode = ({
|
|||||||
shiftValuePos,
|
shiftValuePos,
|
||||||
bold,
|
bold,
|
||||||
}) => {
|
}) => {
|
||||||
const kValue = kFormatter(value);
|
let kValue
|
||||||
|
if (isNaN(value)) {
|
||||||
|
kValue = value;
|
||||||
|
} else {
|
||||||
|
kValue = kFormatter(value);
|
||||||
|
}
|
||||||
const staggerDelay = (index + 3) * 150;
|
const staggerDelay = (index + 3) * 150;
|
||||||
|
|
||||||
const labelOffset = showIcons ? `x="25"` : "";
|
const labelOffset = showIcons ? `x="25"` : "";
|
||||||
@@ -75,15 +80,6 @@ const createTextNode = ({
|
|||||||
* @returns {string} The stats card SVG object.
|
* @returns {string} The stats card SVG object.
|
||||||
*/
|
*/
|
||||||
const renderStatsCard = (stats = {}, options = { hide: [] }) => {
|
const renderStatsCard = (stats = {}, options = { hide: [] }) => {
|
||||||
const {
|
|
||||||
name,
|
|
||||||
totalStars,
|
|
||||||
totalCommits,
|
|
||||||
totalIssues,
|
|
||||||
totalPRs,
|
|
||||||
contributedTo,
|
|
||||||
rank,
|
|
||||||
} = stats;
|
|
||||||
const {
|
const {
|
||||||
hide = [],
|
hide = [],
|
||||||
show_icons = false,
|
show_icons = false,
|
||||||
@@ -106,6 +102,37 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
|
|||||||
locale,
|
locale,
|
||||||
disable_animations = false,
|
disable_animations = false,
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
|
const name = stats.name || "GitHub User"
|
||||||
|
|
||||||
|
const apostrophe = ["x", "s"].includes(name.slice(-1).toLocaleLowerCase())
|
||||||
|
? ""
|
||||||
|
: "s";
|
||||||
|
|
||||||
|
const i18n = new I18n({
|
||||||
|
locale,
|
||||||
|
translations: statCardLocales({ name, apostrophe }),
|
||||||
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
totalStars = "2018",
|
||||||
|
totalCommits = "29019",
|
||||||
|
totalIssues = "203",
|
||||||
|
totalPRs = "127",
|
||||||
|
contributedTo = "232",
|
||||||
|
rank = {
|
||||||
|
level: "S",
|
||||||
|
score: 10
|
||||||
|
},
|
||||||
|
starsTitle = i18n.t("statcard.totalstars"),
|
||||||
|
commitsTitle = `${i18n.t("statcard.commits")}${
|
||||||
|
include_all_commits ? "" : ` (${new Date().getFullYear()})`
|
||||||
|
}`,
|
||||||
|
issuesTitle = i18n.t("statcard.issues"),
|
||||||
|
PRsTitle = i18n.t("statcard.prs"),
|
||||||
|
contribsTitle = i18n.t("statcard.contribs") + " (last year)",
|
||||||
|
title = i18n.t("statcard.title"),
|
||||||
|
} = stats;
|
||||||
|
|
||||||
const lheight = parseInt(String(line_height), 10);
|
const lheight = parseInt(String(line_height), 10);
|
||||||
|
|
||||||
@@ -121,45 +148,35 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
|
|||||||
theme,
|
theme,
|
||||||
});
|
});
|
||||||
|
|
||||||
const apostrophe = ["x", "s"].includes(name.slice(-1).toLocaleLowerCase())
|
|
||||||
? ""
|
|
||||||
: "s";
|
|
||||||
const i18n = new I18n({
|
|
||||||
locale,
|
|
||||||
translations: statCardLocales({ name, apostrophe }),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Meta data for creating text nodes with createTextNode function
|
// Meta data for creating text nodes with createTextNode function
|
||||||
const STATS = {
|
const STATS = {
|
||||||
stars: {
|
stars: {
|
||||||
icon: icons.star,
|
icon: icons.star,
|
||||||
label: i18n.t("statcard.totalstars"),
|
label: starsTitle,
|
||||||
value: totalStars,
|
value: totalStars,
|
||||||
id: "stars",
|
id: "stars",
|
||||||
},
|
},
|
||||||
commits: {
|
commits: {
|
||||||
icon: icons.commits,
|
icon: icons.commits,
|
||||||
label: `${i18n.t("statcard.commits")}${
|
label: commitsTitle,
|
||||||
include_all_commits ? "" : ` (${new Date().getFullYear()})`
|
|
||||||
}`,
|
|
||||||
value: totalCommits,
|
value: totalCommits,
|
||||||
id: "commits",
|
id: "commits",
|
||||||
},
|
},
|
||||||
prs: {
|
prs: {
|
||||||
icon: icons.prs,
|
icon: icons.prs,
|
||||||
label: i18n.t("statcard.prs"),
|
label: PRsTitle,
|
||||||
value: totalPRs,
|
value: totalPRs,
|
||||||
id: "prs",
|
id: "prs",
|
||||||
},
|
},
|
||||||
issues: {
|
issues: {
|
||||||
icon: icons.issues,
|
icon: icons.issues,
|
||||||
label: i18n.t("statcard.issues"),
|
label: issuesTitle,
|
||||||
value: totalIssues,
|
value: totalIssues,
|
||||||
id: "issues",
|
id: "issues",
|
||||||
},
|
},
|
||||||
contribs: {
|
contribs: {
|
||||||
icon: icons.contribs,
|
icon: icons.contribs,
|
||||||
label: i18n.t("statcard.contribs") + " (last year)",
|
label: contribsTitle,
|
||||||
value: contributedTo,
|
value: contributedTo,
|
||||||
id: "contribs",
|
id: "contribs",
|
||||||
},
|
},
|
||||||
@@ -215,7 +232,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const calculateTextWidth = () => {
|
const calculateTextWidth = () => {
|
||||||
return measureText(custom_title ? custom_title : i18n.t("statcard.title"));
|
return measureText(custom_title ? custom_title : title);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -241,7 +258,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
|
|||||||
|
|
||||||
const card = new Card({
|
const card = new Card({
|
||||||
customTitle: custom_title,
|
customTitle: custom_title,
|
||||||
defaultTitle: i18n.t("statcard.title"),
|
defaultTitle: title,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
border_radius,
|
border_radius,
|
||||||
@@ -306,11 +323,6 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
|
|||||||
const labels = Object.keys(STATS)
|
const labels = Object.keys(STATS)
|
||||||
.filter((key) => !hide.includes(key))
|
.filter((key) => !hide.includes(key))
|
||||||
.map((key) => {
|
.map((key) => {
|
||||||
if (key === "commits") {
|
|
||||||
return `${i18n.t("statcard.commits")} ${
|
|
||||||
include_all_commits ? "" : `in ${new Date().getFullYear()}`
|
|
||||||
} : ${totalStars}`;
|
|
||||||
}
|
|
||||||
return `${STATS[key].label}: ${STATS[key].value}`;
|
return `${STATS[key].label}: ${STATS[key].value}`;
|
||||||
})
|
})
|
||||||
.join(", ");
|
.join(", ");
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ const getLongestLang = (arr) =>
|
|||||||
* @param {number} props.index Index of the programming language.
|
* @param {number} props.index Index of the programming language.
|
||||||
* @returns {string} Programming language SVG node.
|
* @returns {string} Programming language SVG node.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const createProgressTextNode = ({ width, color, name, progress, index }) => {
|
const createProgressTextNode = ({ width, color, name, progress, index }) => {
|
||||||
const staggerDelay = (index + 3) * 150;
|
const staggerDelay = (index + 3) * 150;
|
||||||
const paddingRight = 95;
|
const paddingRight = 95;
|
||||||
@@ -56,7 +57,7 @@ const createProgressTextNode = ({ width, color, name, progress, index }) => {
|
|||||||
return `
|
return `
|
||||||
<g class="stagger" style="animation-delay: ${staggerDelay}ms">
|
<g class="stagger" style="animation-delay: ${staggerDelay}ms">
|
||||||
<text data-testid="lang-name" x="2" y="15" class="lang-name">${name}</text>
|
<text data-testid="lang-name" x="2" y="15" class="lang-name">${name}</text>
|
||||||
<text x="${progressTextX}" y="34" class="lang-name">${progress}%</text>
|
<text x="${progressTextX}" y="34" class="lang-name">${text || `${progress}%`}</text>
|
||||||
${createProgressNode({
|
${createProgressNode({
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 25,
|
y: 25,
|
||||||
@@ -89,7 +90,7 @@ const createCompactLangNode = ({ lang, totalSize, hideProgress, index }) => {
|
|||||||
<g class="stagger" style="animation-delay: ${staggerDelay}ms">
|
<g class="stagger" style="animation-delay: ${staggerDelay}ms">
|
||||||
<circle cx="5" cy="6" r="5" fill="${color}" />
|
<circle cx="5" cy="6" r="5" fill="${color}" />
|
||||||
<text data-testid="lang-name" x="15" y="10" class='lang-name'>
|
<text data-testid="lang-name" x="15" y="10" class='lang-name'>
|
||||||
${lang.name} ${hideProgress ? "" : percentage + "%"}
|
${lang.name} ${hideProgress ? "" : (lang.text || `${percentage}%`)}
|
||||||
</text>
|
</text>
|
||||||
</g>
|
</g>
|
||||||
`;
|
`;
|
||||||
@@ -126,7 +127,7 @@ const createLanguageTextNode = ({ langs, totalSize, hideProgress }) => {
|
|||||||
|
|
||||||
const percent = ((longestLang.size / totalSize) * 100).toFixed(2);
|
const percent = ((longestLang.size / totalSize) * 100).toFixed(2);
|
||||||
const minGap = 150;
|
const minGap = 150;
|
||||||
const maxGap = 20 + measureText(`${longestLang.name} ${percent}%`, 11);
|
const maxGap = 20 + measureText(`${longestLang.name} ${longestLang.text || `${percent}%`}`, 11);
|
||||||
return flexLayout({
|
return flexLayout({
|
||||||
items: layouts,
|
items: layouts,
|
||||||
gap: maxGap < minGap ? minGap : maxGap,
|
gap: maxGap < minGap ? minGap : maxGap,
|
||||||
@@ -149,6 +150,7 @@ const renderNormalLayout = (langs, width, totalLanguageSize) => {
|
|||||||
name: lang.name,
|
name: lang.name,
|
||||||
color: lang.color || DEFAULT_LANG_COLOR,
|
color: lang.color || DEFAULT_LANG_COLOR,
|
||||||
progress: ((lang.size / totalLanguageSize) * 100).toFixed(2),
|
progress: ((lang.size / totalLanguageSize) * 100).toFixed(2),
|
||||||
|
text: lang.text,
|
||||||
index,
|
index,
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
@@ -278,6 +280,12 @@ const useLanguages = (topLangs, hide, langs_count) => {
|
|||||||
* @returns {string} Language card SVG object.
|
* @returns {string} Language card SVG object.
|
||||||
*/
|
*/
|
||||||
const renderTopLanguages = (topLangs, options = {}) => {
|
const renderTopLanguages = (topLangs, options = {}) => {
|
||||||
|
const locale = options.locale
|
||||||
|
const i18n = new I18n({
|
||||||
|
locale,
|
||||||
|
translations: langCardLocales,
|
||||||
|
});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
hide_title = false,
|
hide_title = false,
|
||||||
hide_border,
|
hide_border,
|
||||||
@@ -290,18 +298,13 @@ const renderTopLanguages = (topLangs, options = {}) => {
|
|||||||
theme,
|
theme,
|
||||||
layout,
|
layout,
|
||||||
custom_title,
|
custom_title,
|
||||||
locale,
|
|
||||||
langs_count = DEFAULT_LANGS_COUNT,
|
langs_count = DEFAULT_LANGS_COUNT,
|
||||||
border_radius,
|
border_radius,
|
||||||
border_color,
|
border_color,
|
||||||
|
title = i18n.t("langcard.title"),
|
||||||
disable_animations,
|
disable_animations,
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
const i18n = new I18n({
|
|
||||||
locale,
|
|
||||||
translations: langCardLocales,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { langs, totalLanguageSize } = useLanguages(
|
const { langs, totalLanguageSize } = useLanguages(
|
||||||
topLangs,
|
topLangs,
|
||||||
hide,
|
hide,
|
||||||
@@ -342,7 +345,7 @@ const renderTopLanguages = (topLangs, options = {}) => {
|
|||||||
|
|
||||||
const card = new Card({
|
const card = new Card({
|
||||||
customTitle: custom_title,
|
customTitle: custom_title,
|
||||||
defaultTitle: i18n.t("langcard.title"),
|
defaultTitle: title,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
border_radius,
|
border_radius,
|
||||||
|
|||||||
Reference in New Issue
Block a user