Compare commits

...
Author SHA1 Message Date
Zohan Subhash e5ba3238ab Update readme.md 2023-02-18 12:25:52 +05:30
Zohan Subhash f4e731ee09 Delete top-langs.js 2023-02-18 12:23:14 +05:30
Zohan Subhash 6f07b51c00 Delete pin.js 2023-02-18 12:23:10 +05:30
Zohan Subhash 6e0522cdd9 Delete index.js 2023-02-18 12:23:06 +05:30
Zohan Subhash 4ce744f7b5 Merge pull request #2527 from Zo-Bro-23/custom-cards
Transfer branch from my fork to main repo
2023-02-18 12:22:23 +05:30
Zohan Subhash 3565f25c46 Merge branch 'zo/custom-cards' into custom-cards 2023-02-18 12:21:53 +05:30
Zohan Subhash a5114d12d0 Update top-langs.js 2023-01-26 16:52:36 +05:30
Zohan Subhash 20914797b0 Disable cache 2023-01-26 16:52:18 +05:30
Zohan Subhash 11cb8dffc1 Disable cache 2023-01-26 16:51:40 +05:30
Zohan Subhash a885425b52 Update readme.md 2023-01-17 17:07:41 +05:30
Zohan Subhash 017e3ba180 Update readme.md 2023-01-17 16:54:56 +05:30
Zohan Subhash 03465922b0 Update readme.md 2023-01-17 16:49:19 +05:30
Zohan Subhash 9829ab990d Update readme.md 2023-01-17 16:47:22 +05:30
Zohan Subhash 6243c702c3 Update top-langs.js 2023-01-17 16:33:50 +05:30
Zohan Subhash 97cef21e4e Update repo-card.js 2023-01-17 16:09:08 +05:30
Zohan Subhash 55a3cecd49 Update repo-card.js 2023-01-17 16:07:42 +05:30
Zohan Subhash e245941e5a Update repo-card.js 2023-01-17 16:05:24 +05:30
Zohan Subhash 04ed2bdd3f Update repo-card.js 2023-01-17 16:02:23 +05:30
Zohan Subhash c33f3f617a Update repo-card.js 2023-01-17 15:59:11 +05:30
Zohan Subhash 589badc483 Update pin.js 2023-01-17 15:57:59 +05:30
Zohan Subhash 05b611ad58 Update pin.js 2023-01-17 15:55:42 +05:30
Zohan Subhash bf0a15f94f Update pin.js 2023-01-17 15:52:46 +05:30
Zohan Subhash b8425d36c8 Update repo-card.js 2023-01-17 15:51:33 +05:30
Zohan Subhash 866e509d07 Create pin.js 2023-01-17 15:49:21 +05:30
Zohan Subhash c1e2858330 Update repo-card.js 2023-01-17 15:47:39 +05:30
Zohan Subhash 01f726c316 Update repo-card.js 2023-01-17 15:43:37 +05:30
Zohan Subhash 2770161e33 Update top-languages-card.js 2023-01-16 16:40:12 +05:30
Zohan Subhash b320054e90 Update top-languages-card.js 2023-01-16 16:38:33 +05:30
Zohan Subhash 5675ce77b1 Update top-langs.js 2023-01-16 16:37:25 +05:30
Zohan Subhash 27029cd565 Update top-languages-card.js 2023-01-16 16:35:32 +05:30
Zohan Subhash df42981d34 Update top-langs.js 2023-01-16 16:34:14 +05:30
Zohan Subhash 4ecebbca94 Update top-languages-card.js 2023-01-16 16:28:51 +05:30
Zohan Subhash 80e6d0acc5 Update top-languages-card.js 2023-01-16 16:26:44 +05:30
Zohan Subhash 0adcb158f9 Update top-languages-card.js 2023-01-16 16:21:00 +05:30
Zohan Subhash 2cb4861b24 Update top-langs.js 2023-01-16 16:14:59 +05:30
Zohan Subhash 3cebd8907b Update top-languages-card.js 2023-01-16 16:14:14 +05:30
Zohan Subhash 42503cf90c Update top-langs.js 2023-01-16 15:43:03 +05:30
Zohan Subhash 2466713261 Update top-langs.js 2023-01-16 15:37:18 +05:30
Zohan Subhash 9c08efedbf Update top-langs.js 2023-01-16 15:37:02 +05:30
Zohan Subhash af36d0b2e1 Update top-langs.js 2023-01-16 15:32:22 +05:30
Zohan Subhash 1689ca6feb Update top-langs.js 2023-01-16 15:31:04 +05:30
Zohan Subhash 642d63d4f0 Update top-langs.js 2023-01-16 15:23:20 +05:30
Zohan Subhash 2a1d255e45 Update top-langs.js 2023-01-16 15:12:05 +05:30
Zohan Subhash 114225e72e Update top-langs.js 2023-01-15 16:04:55 +05:30
Zohan Subhash cc558e4d7c Update top-langs.js 2023-01-15 16:01:17 +05:30
Zohan Subhash 6738c6db5f Update top-langs.js 2023-01-15 15:57:10 +05:30
Zohan Subhash ede2574b13 Update top-langs.js 2023-01-15 15:55:48 +05:30
Zohan Subhash c6ca64551e Update top-langs.js 2023-01-15 15:49:01 +05:30
Zohan Subhash 5448a611ba Create top-langs.js 2023-01-15 15:47:18 +05:30
Zohan Subhash 22aa6887f9 Update index.js 2023-01-15 15:43:28 +05:30
Zohan Subhash ffd927af6d Update top-languages-card.js 2023-01-15 15:39:54 +05:30
Zohan Subhash f02186908d Update stats-card.js 2023-01-14 11:59:30 +05:30
Zohan Subhash 8f63eaeef9 Update stats-card.js 2023-01-14 11:57:53 +05:30
Zohan Subhash 70b0d025f8 Update index.js 2023-01-14 11:54:14 +05:30
Zohan Subhash dc95c44c22 Update index.js 2023-01-14 11:52:06 +05:30
Zohan Subhash adbc7a36c9 Update stats-card.js 2023-01-14 11:51:44 +05:30
Zohan Subhash 1651db55ec Update index.js 2023-01-14 11:47:12 +05:30
Zohan Subhash e40f214a76 Create index.js 2023-01-14 11:46:26 +05:30
Zohan Subhash 88aa6fe30c Update stats-card.js 2023-01-14 11:44:44 +05:30
Zohan Subhash ad731cdfcb Update stats-card.js 2023-01-14 11:17:00 +05:30
Zohan Subhash 237942c234 Update index.js 2023-01-14 10:57:44 +05:30
Zohan Subhash d505580a4f Update index.js 2023-01-14 10:55:44 +05:30
Zohan Subhash 4dbab9a2a3 Update stats-card.js 2023-01-14 10:55:12 +05:30
Zohan Subhash d8af18e465 Update stats-card.js 2023-01-14 10:52:26 +05:30
Zohan Subhash 1af63921b5 Update index.js 2023-01-14 10:46:44 +05:30
Zohan Subhash 9ff83e0855 Update index.js 2023-01-14 10:41:30 +05:30
Zohan Subhash 6349ec8f32 Update stats-card.js 2023-01-14 10:40:56 +05:30
Zohan Subhash 31f2920c09 Update vercel.json 2023-01-14 08:02:31 +05:30
Zohan Subhash 19cf691983 Update index.js 2023-01-13 18:52:41 +05:30
Zohan Subhash 36e838da62 Update stats-card.js 2023-01-13 18:48:32 +05:30
3 changed files with 108 additions and 77 deletions
+51 -35
View File
@@ -87,16 +87,6 @@ const iconWithLabel = (icon, label, testid) => {
* @returns {string} Repository card SVG object.
*/
const renderRepoCard = (repo, options = {}) => {
const {
name,
nameWithOwner,
description,
primaryLanguage,
isArchived,
isTemplate,
starCount,
forkCount,
} = repo;
const {
hide_border = false,
title_color,
@@ -109,6 +99,42 @@ const renderRepoCard = (repo, options = {}) => {
border_color,
locale,
} = 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 header = show_owner ? nameWithOwner : name;
@@ -125,27 +151,25 @@ const renderRepoCard = (repo, options = {}) => {
const height =
(descriptionLines > 1 ? 120 : 110) + descriptionLines * lineHeight;
const i18n = new I18n({
locale,
translations: repoCardLocales,
});
// 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
? createLanguageNode(langName, langColor)
: "";
const totalStars = kFormatter(starCount);
const totalForks = kFormatter(forkCount);
let totalStars
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 svgForks = iconWithLabel(icons.fork, totalForks, "forkcount");
@@ -180,15 +204,7 @@ const renderRepoCard = (repo, options = {}) => {
`);
return card.render(`
${
isTemplate
? // @ts-ignore
getBadgeSVG(i18n.t("repocard.template"), colors.textColor)
: isArchived
? // @ts-ignore
getBadgeSVG(i18n.t("repocard.archived"), colors.textColor)
: ""
}
${highlight}
<text class="description" x="25" y="-5">
${descriptionSvg}
+44 -32
View File
@@ -40,7 +40,12 @@ const createTextNode = ({
shiftValuePos,
bold,
}) => {
const kValue = kFormatter(value);
let kValue
if (isNaN(value)) {
kValue = value;
} else {
kValue = kFormatter(value);
}
const staggerDelay = (index + 3) * 150;
const labelOffset = showIcons ? `x="25"` : "";
@@ -75,15 +80,6 @@ const createTextNode = ({
* @returns {string} The stats card SVG object.
*/
const renderStatsCard = (stats = {}, options = { hide: [] }) => {
const {
name,
totalStars,
totalCommits,
totalIssues,
totalPRs,
contributedTo,
rank,
} = stats;
const {
hide = [],
show_icons = false,
@@ -106,6 +102,37 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
locale,
disable_animations = false,
} = 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);
@@ -121,45 +148,35 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
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
const STATS = {
stars: {
icon: icons.star,
label: i18n.t("statcard.totalstars"),
label: starsTitle,
value: totalStars,
id: "stars",
},
commits: {
icon: icons.commits,
label: `${i18n.t("statcard.commits")}${
include_all_commits ? "" : ` (${new Date().getFullYear()})`
}`,
label: commitsTitle,
value: totalCommits,
id: "commits",
},
prs: {
icon: icons.prs,
label: i18n.t("statcard.prs"),
label: PRsTitle,
value: totalPRs,
id: "prs",
},
issues: {
icon: icons.issues,
label: i18n.t("statcard.issues"),
label: issuesTitle,
value: totalIssues,
id: "issues",
},
contribs: {
icon: icons.contribs,
label: i18n.t("statcard.contribs") + " (last year)",
label: contribsTitle,
value: contributedTo,
id: "contribs",
},
@@ -215,7 +232,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
});
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({
customTitle: custom_title,
defaultTitle: i18n.t("statcard.title"),
defaultTitle: title,
width,
height,
border_radius,
@@ -306,11 +323,6 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
const labels = Object.keys(STATS)
.filter((key) => !hide.includes(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}`;
})
.join(", ");
+13 -10
View File
@@ -47,6 +47,7 @@ const getLongestLang = (arr) =>
* @param {number} props.index Index of the programming language.
* @returns {string} Programming language SVG node.
*/
const createProgressTextNode = ({ width, color, name, progress, index }) => {
const staggerDelay = (index + 3) * 150;
const paddingRight = 95;
@@ -56,7 +57,7 @@ const createProgressTextNode = ({ width, color, name, progress, index }) => {
return `
<g class="stagger" style="animation-delay: ${staggerDelay}ms">
<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({
x: 0,
y: 25,
@@ -89,7 +90,7 @@ const createCompactLangNode = ({ lang, totalSize, hideProgress, index }) => {
<g class="stagger" style="animation-delay: ${staggerDelay}ms">
<circle cx="5" cy="6" r="5" fill="${color}" />
<text data-testid="lang-name" x="15" y="10" class='lang-name'>
${lang.name} ${hideProgress ? "" : percentage + "%"}
${lang.name} ${hideProgress ? "" : (lang.text || `${percentage}%`)}
</text>
</g>
`;
@@ -126,7 +127,7 @@ const createLanguageTextNode = ({ langs, totalSize, hideProgress }) => {
const percent = ((longestLang.size / totalSize) * 100).toFixed(2);
const minGap = 150;
const maxGap = 20 + measureText(`${longestLang.name} ${percent}%`, 11);
const maxGap = 20 + measureText(`${longestLang.name} ${longestLang.text || `${percent}%`}`, 11);
return flexLayout({
items: layouts,
gap: maxGap < minGap ? minGap : maxGap,
@@ -149,6 +150,7 @@ const renderNormalLayout = (langs, width, totalLanguageSize) => {
name: lang.name,
color: lang.color || DEFAULT_LANG_COLOR,
progress: ((lang.size / totalLanguageSize) * 100).toFixed(2),
text: lang.text,
index,
});
}),
@@ -278,6 +280,12 @@ const useLanguages = (topLangs, hide, langs_count) => {
* @returns {string} Language card SVG object.
*/
const renderTopLanguages = (topLangs, options = {}) => {
const locale = options.locale
const i18n = new I18n({
locale,
translations: langCardLocales,
});
const {
hide_title = false,
hide_border,
@@ -290,18 +298,13 @@ const renderTopLanguages = (topLangs, options = {}) => {
theme,
layout,
custom_title,
locale,
langs_count = DEFAULT_LANGS_COUNT,
border_radius,
border_color,
title = i18n.t("langcard.title"),
disable_animations,
} = options;
const i18n = new I18n({
locale,
translations: langCardLocales,
});
const { langs, totalLanguageSize } = useLanguages(
topLangs,
hide,
@@ -342,7 +345,7 @@ const renderTopLanguages = (topLangs, options = {}) => {
const card = new Card({
customTitle: custom_title,
defaultTitle: i18n.t("langcard.title"),
defaultTitle: title,
width,
height,
border_radius,