From 36e838da62132246edae1c2166886cc9912200dd Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Fri, 13 Jan 2023 18:48:32 +0530 Subject: [PATCH 01/64] Update stats-card.js --- src/cards/stats-card.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/cards/stats-card.js b/src/cards/stats-card.js index a049ecce1c7e3..7181feba1f11e 100644 --- a/src/cards/stats-card.js +++ b/src/cards/stats-card.js @@ -78,6 +78,12 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { totalPRs, contributedTo, rank, + starsTitle, + commitsTitle, + issuesTitle, + PRsTitle, + contribsTitle, + title, } = stats; const { hide = [], @@ -128,33 +134,31 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { 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", }, @@ -210,7 +214,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { }); const calculateTextWidth = () => { - return measureText(custom_title ? custom_title : i18n.t("statcard.title")); + return measureText(title); }; /* @@ -230,7 +234,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { const card = new Card({ customTitle: custom_title, - defaultTitle: i18n.t("statcard.title"), + defaultTitle: title, width, height, border_radius, @@ -293,9 +297,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { .filter((key) => !hide.includes(key)) .map((key) => { if (key === "commits") { - return `${i18n.t("statcard.commits")} ${ - include_all_commits ? "" : `in ${new Date().getFullYear()}` - } : ${totalStars}`; + return commitsTitle; } return `${STATS[key].label}: ${STATS[key].value}`; }) From 19cf6919832389f27ae7e74ccee313e6d35b231d Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Fri, 13 Jan 2023 18:52:41 +0530 Subject: [PATCH 02/64] Update index.js --- api/index.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/api/index.js b/api/index.js index b449d43b49080..13d6c1f703ceb 100644 --- a/api/index.js +++ b/api/index.js @@ -48,12 +48,20 @@ export default async (req, res) => { } try { - const stats = await fetchStats( - username, - parseBoolean(count_private), - parseBoolean(include_all_commits), - parseArray(exclude_repo), - ); + const stats = { + req.query.totalStars, + req.query.totalCommits, + req.query.totalIssues, + req.query.totalPRs, + req.query.contributedTo, + req.query.rank, + req.query.starsTitle, + req.query.commitsTitle, + req.query.issuesTitle, + req.query.PRsTitle, + req.query.contribsTitle, + req.query.title, + }; const cacheSeconds = clampValue( parseInt(cache_seconds || CONSTANTS.FOUR_HOURS, 10), From 31f2920c09b3236014a26993d147be6e603b9bc1 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sat, 14 Jan 2023 08:02:31 +0530 Subject: [PATCH 03/64] Update vercel.json --- vercel.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vercel.json b/vercel.json index aee61ce054fd0..ddf82eb15666f 100644 --- a/vercel.json +++ b/vercel.json @@ -2,7 +2,7 @@ "functions": { "api/*.js": { "memory": 128, - "maxDuration": 30 + "maxDuration": 10 } }, "redirects": [ From 6349ec8f32c6d1902fe16e090cfd51b030361d97 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sat, 14 Jan 2023 10:40:56 +0530 Subject: [PATCH 04/64] Update stats-card.js --- src/cards/stats-card.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/cards/stats-card.js b/src/cards/stats-card.js index 7181feba1f11e..9e0a1b606cab7 100644 --- a/src/cards/stats-card.js +++ b/src/cards/stats-card.js @@ -71,19 +71,19 @@ const createTextNode = ({ */ const renderStatsCard = (stats = {}, options = { hide: [] }) => { const { - name, - totalStars, - totalCommits, - totalIssues, - totalPRs, - contributedTo, - rank, - starsTitle, - commitsTitle, - issuesTitle, - PRsTitle, - contribsTitle, - title, + name = "GitHub User", + totalStars = "2018", + totalCommits = "29019", + totalIssues = "203", + totalPRs = "127", + contributedTo = "232", + rank = "S", + starsTitle = "Total Stars:", + commitsTitle = "Total Commits:", + issuesTitle = "Total Issues:", + PRsTitle = "Total PRs:", + contribsTitle = "Total Contributions:", + title = "Your GitHub Stats", } = stats; const { hide = [], From 9ff83e08558e955ec9012164c2916e33670d1f04 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sat, 14 Jan 2023 10:41:30 +0530 Subject: [PATCH 05/64] Update index.js --- api/index.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/api/index.js b/api/index.js index 13d6c1f703ceb..2c41a14f16e07 100644 --- a/api/index.js +++ b/api/index.js @@ -49,19 +49,19 @@ export default async (req, res) => { try { const stats = { - req.query.totalStars, - req.query.totalCommits, - req.query.totalIssues, - req.query.totalPRs, - req.query.contributedTo, - req.query.rank, - req.query.starsTitle, - req.query.commitsTitle, - req.query.issuesTitle, - req.query.PRsTitle, - req.query.contribsTitle, - req.query.title, - }; + totalStars, + totalCommits, + totalIssues, + totalPRs, + contributedTo, + rank, + starsTitle, + commitsTitle, + issuesTitle, + PRsTitle, + contribsTitle, + title, + } = req.query; const cacheSeconds = clampValue( parseInt(cache_seconds || CONSTANTS.FOUR_HOURS, 10), From 1af63921b559d3f6435199b9f60c2e2b5b3d9aa7 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sat, 14 Jan 2023 10:46:44 +0530 Subject: [PATCH 06/64] Update index.js --- api/index.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/api/index.js b/api/index.js index 2c41a14f16e07..f8ea29246dae7 100644 --- a/api/index.js +++ b/api/index.js @@ -49,19 +49,19 @@ export default async (req, res) => { try { const stats = { - totalStars, - totalCommits, - totalIssues, - totalPRs, - contributedTo, - rank, - starsTitle, - commitsTitle, - issuesTitle, - PRsTitle, - contribsTitle, - title, - } = req.query; + totalStars: req.query.totalStars, + totalCommits: req.query.totalCommits, + totalIssues: req.query.totalIssues, + totalPRs: req.query.totalPRs, + contributedTo: req.query.contributedTo, + rank: req.query.rank, + starsTitle: req.query.starsTitle, + commitsTitle: req.query.commitsTitle, + issuesTitle: req.query.issuesTitle, + PRsTitle: req.query.PRsTitle, + contribsTitle: req.query.contribsTitle, + title: req.query.title, + }; const cacheSeconds = clampValue( parseInt(cache_seconds || CONSTANTS.FOUR_HOURS, 10), From d8af18e465baf0c7f645a37d6919e4fef7d84239 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sat, 14 Jan 2023 10:52:26 +0530 Subject: [PATCH 07/64] Update stats-card.js --- src/cards/stats-card.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/cards/stats-card.js b/src/cards/stats-card.js index 9e0a1b606cab7..14e854054b551 100644 --- a/src/cards/stats-card.js +++ b/src/cards/stats-card.js @@ -77,12 +77,15 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { totalIssues = "203", totalPRs = "127", contributedTo = "232", - rank = "S", - starsTitle = "Total Stars:", - commitsTitle = "Total Commits:", - issuesTitle = "Total Issues:", - PRsTitle = "Total PRs:", - contribsTitle = "Total Contributions:", + rank = { + level: "S", + score: 90 + }, + starsTitle = "Total Stars", + commitsTitle = "Total Commits", + issuesTitle = "Total Issues", + PRsTitle = "Total PRs", + contribsTitle = "Total Contributions", title = "Your GitHub Stats", } = stats; const { From 4dbab9a2a37e673eff4daa3dc04ffa516338c994 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sat, 14 Jan 2023 10:55:12 +0530 Subject: [PATCH 08/64] Update stats-card.js --- src/cards/stats-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cards/stats-card.js b/src/cards/stats-card.js index 14e854054b551..b87fdd620f467 100644 --- a/src/cards/stats-card.js +++ b/src/cards/stats-card.js @@ -79,7 +79,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { contributedTo = "232", rank = { level: "S", - score: 90 + score: 10 }, starsTitle = "Total Stars", commitsTitle = "Total Commits", From d505580a4f9a9b0a24828230fbb3779a4786b6c5 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sat, 14 Jan 2023 10:55:44 +0530 Subject: [PATCH 09/64] Update index.js --- api/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/api/index.js b/api/index.js index f8ea29246dae7..3e4c68b078696 100644 --- a/api/index.js +++ b/api/index.js @@ -54,7 +54,10 @@ export default async (req, res) => { totalIssues: req.query.totalIssues, totalPRs: req.query.totalPRs, contributedTo: req.query.contributedTo, - rank: req.query.rank, + rank: { + level: req.query.level, + score: req.query.score + }, starsTitle: req.query.starsTitle, commitsTitle: req.query.commitsTitle, issuesTitle: req.query.issuesTitle, From 237942c234571c7bf6894ec3ba7ccae149eb510b Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sat, 14 Jan 2023 10:57:44 +0530 Subject: [PATCH 10/64] Update index.js --- api/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/index.js b/api/index.js index 3e4c68b078696..cc6e75e9f0dcf 100644 --- a/api/index.js +++ b/api/index.js @@ -55,8 +55,8 @@ export default async (req, res) => { totalPRs: req.query.totalPRs, contributedTo: req.query.contributedTo, rank: { - level: req.query.level, - score: req.query.score + level: req.query.level || 'S', + score: req.query.score || 10 }, starsTitle: req.query.starsTitle, commitsTitle: req.query.commitsTitle, From ad731cdfcb712c5245110cd7a0f4e4504c3044c5 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sat, 14 Jan 2023 11:17:00 +0530 Subject: [PATCH 11/64] Update stats-card.js --- src/cards/stats-card.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cards/stats-card.js b/src/cards/stats-card.js index b87fdd620f467..8b784fdb70b93 100644 --- a/src/cards/stats-card.js +++ b/src/cards/stats-card.js @@ -35,7 +35,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"` : ""; From 88aa6fe30cfc1d1e148d3a27fa67170465a3bad2 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sat, 14 Jan 2023 11:44:44 +0530 Subject: [PATCH 12/64] Update stats-card.js --- src/cards/stats-card.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/cards/stats-card.js b/src/cards/stats-card.js index 8b784fdb70b93..0b506a335dc22 100644 --- a/src/cards/stats-card.js +++ b/src/cards/stats-card.js @@ -36,10 +36,10 @@ const createTextNode = ({ bold, }) => { let kValue - if(isNaN(value)){ - kValue = value + if (isNaN(value)) { + kValue = value; } else { - kValue = kFormatter(value) + kValue = kFormatter(value); } const staggerDelay = (index + 3) * 150; @@ -86,12 +86,14 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { level: "S", score: 10 }, - starsTitle = "Total Stars", - commitsTitle = "Total Commits", - issuesTitle = "Total Issues", - PRsTitle = "Total PRs", - contribsTitle = "Total Contributions", - title = "Your GitHub Stats", + 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 { hide = [], @@ -222,7 +224,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { }); const calculateTextWidth = () => { - return measureText(title); + return measureText(custom_title ? custom_title : title); }; /* @@ -304,9 +306,6 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { const labels = Object.keys(STATS) .filter((key) => !hide.includes(key)) .map((key) => { - if (key === "commits") { - return commitsTitle; - } return `${STATS[key].label}: ${STATS[key].value}`; }) .join(", "); From e40f214a76d625cb06ecc0a057510ca63b16bfb4 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sat, 14 Jan 2023 11:46:26 +0530 Subject: [PATCH 13/64] Create index.js --- api/wild/index.js | 110 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 api/wild/index.js diff --git a/api/wild/index.js b/api/wild/index.js new file mode 100644 index 0000000000000..cc6e75e9f0dcf --- /dev/null +++ b/api/wild/index.js @@ -0,0 +1,110 @@ +import { renderStatsCard } from "../src/cards/stats-card.js"; +import { blacklist } from "../src/common/blacklist.js"; +import { + clampValue, + CONSTANTS, + parseArray, + parseBoolean, + renderError, +} from "../src/common/utils.js"; +import { fetchStats } from "../src/fetchers/stats-fetcher.js"; +import { isLocaleAvailable } from "../src/translations.js"; + +export default async (req, res) => { + const { + username, + hide, + hide_title, + hide_border, + card_width, + hide_rank, + show_icons, + count_private, + include_all_commits, + line_height, + title_color, + ring_color, + icon_color, + text_color, + text_bold, + bg_color, + theme, + cache_seconds, + exclude_repo, + custom_title, + locale, + disable_animations, + border_radius, + border_color, + } = req.query; + res.setHeader("Content-Type", "image/svg+xml"); + + if (blacklist.includes(username)) { + return res.send(renderError("Something went wrong")); + } + + if (locale && !isLocaleAvailable(locale)) { + return res.send(renderError("Something went wrong", "Language not found")); + } + + try { + const stats = { + totalStars: req.query.totalStars, + totalCommits: req.query.totalCommits, + totalIssues: req.query.totalIssues, + totalPRs: req.query.totalPRs, + contributedTo: req.query.contributedTo, + rank: { + level: req.query.level || 'S', + score: req.query.score || 10 + }, + starsTitle: req.query.starsTitle, + commitsTitle: req.query.commitsTitle, + issuesTitle: req.query.issuesTitle, + PRsTitle: req.query.PRsTitle, + contribsTitle: req.query.contribsTitle, + title: req.query.title, + }; + + const cacheSeconds = clampValue( + parseInt(cache_seconds || CONSTANTS.FOUR_HOURS, 10), + CONSTANTS.FOUR_HOURS, + CONSTANTS.ONE_DAY, + ); + + res.setHeader( + "Cache-Control", + `max-age=${ + cacheSeconds / 2 + }, s-maxage=${cacheSeconds}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`, + ); + + return res.send( + renderStatsCard(stats, { + hide: parseArray(hide), + show_icons: parseBoolean(show_icons), + hide_title: parseBoolean(hide_title), + hide_border: parseBoolean(hide_border), + card_width: parseInt(card_width, 10), + hide_rank: parseBoolean(hide_rank), + include_all_commits: parseBoolean(include_all_commits), + line_height, + title_color, + ring_color, + icon_color, + text_color, + text_bold: parseBoolean(text_bold), + bg_color, + theme, + custom_title, + border_radius, + border_color, + locale: locale ? locale.toLowerCase() : null, + disable_animations: parseBoolean(disable_animations), + }), + ); + } catch (err) { + res.setHeader("Cache-Control", `no-cache, no-store, must-revalidate`); // Don't cache error responses. + return res.send(renderError(err.message, err.secondaryMessage)); + } +}; From 1651db55ecf9f2db61c71051f064b8076b21ad6f Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sat, 14 Jan 2023 11:47:12 +0530 Subject: [PATCH 14/64] Update index.js --- api/index.js | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/api/index.js b/api/index.js index cc6e75e9f0dcf..b449d43b49080 100644 --- a/api/index.js +++ b/api/index.js @@ -48,23 +48,12 @@ export default async (req, res) => { } try { - const stats = { - totalStars: req.query.totalStars, - totalCommits: req.query.totalCommits, - totalIssues: req.query.totalIssues, - totalPRs: req.query.totalPRs, - contributedTo: req.query.contributedTo, - rank: { - level: req.query.level || 'S', - score: req.query.score || 10 - }, - starsTitle: req.query.starsTitle, - commitsTitle: req.query.commitsTitle, - issuesTitle: req.query.issuesTitle, - PRsTitle: req.query.PRsTitle, - contribsTitle: req.query.contribsTitle, - title: req.query.title, - }; + const stats = await fetchStats( + username, + parseBoolean(count_private), + parseBoolean(include_all_commits), + parseArray(exclude_repo), + ); const cacheSeconds = clampValue( parseInt(cache_seconds || CONSTANTS.FOUR_HOURS, 10), From adbc7a36c97bc0a9a7a7257b44ea10db37068f7c Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sat, 14 Jan 2023 11:51:44 +0530 Subject: [PATCH 15/64] Update stats-card.js --- src/cards/stats-card.js | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/cards/stats-card.js b/src/cards/stats-card.js index 0b506a335dc22..11f5e98cb7069 100644 --- a/src/cards/stats-card.js +++ b/src/cards/stats-card.js @@ -75,26 +75,6 @@ const createTextNode = ({ * @returns {string} The stats card SVG object. */ const renderStatsCard = (stats = {}, options = { hide: [] }) => { - const { - name = "GitHub User", - 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 { hide = [], show_icons = false, @@ -117,6 +97,26 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { locale, disable_animations = false, } = options; + const { + name = "GitHub User", + 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); From dc95c44c2262c3f212d6953c113cb23edfede3ac Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sat, 14 Jan 2023 11:52:06 +0530 Subject: [PATCH 16/64] Update index.js --- api/wild/index.js | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/api/wild/index.js b/api/wild/index.js index cc6e75e9f0dcf..964a1b845da8a 100644 --- a/api/wild/index.js +++ b/api/wild/index.js @@ -1,5 +1,4 @@ import { renderStatsCard } from "../src/cards/stats-card.js"; -import { blacklist } from "../src/common/blacklist.js"; import { clampValue, CONSTANTS, @@ -7,20 +6,15 @@ import { parseBoolean, renderError, } from "../src/common/utils.js"; -import { fetchStats } from "../src/fetchers/stats-fetcher.js"; -import { isLocaleAvailable } from "../src/translations.js"; export default async (req, res) => { const { - username, hide, hide_title, hide_border, card_width, hide_rank, show_icons, - count_private, - include_all_commits, line_height, title_color, ring_color, @@ -30,23 +24,13 @@ export default async (req, res) => { bg_color, theme, cache_seconds, - exclude_repo, custom_title, - locale, disable_animations, border_radius, border_color, } = req.query; res.setHeader("Content-Type", "image/svg+xml"); - if (blacklist.includes(username)) { - return res.send(renderError("Something went wrong")); - } - - if (locale && !isLocaleAvailable(locale)) { - return res.send(renderError("Something went wrong", "Language not found")); - } - try { const stats = { totalStars: req.query.totalStars, @@ -87,7 +71,6 @@ export default async (req, res) => { hide_border: parseBoolean(hide_border), card_width: parseInt(card_width, 10), hide_rank: parseBoolean(hide_rank), - include_all_commits: parseBoolean(include_all_commits), line_height, title_color, ring_color, @@ -99,7 +82,6 @@ export default async (req, res) => { custom_title, border_radius, border_color, - locale: locale ? locale.toLowerCase() : null, disable_animations: parseBoolean(disable_animations), }), ); From 70b0d025f846bf2a450a81eb558afc0f636f808a Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sat, 14 Jan 2023 11:54:14 +0530 Subject: [PATCH 17/64] Update index.js --- api/wild/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/wild/index.js b/api/wild/index.js index 964a1b845da8a..a42a22edf1c18 100644 --- a/api/wild/index.js +++ b/api/wild/index.js @@ -1,11 +1,11 @@ -import { renderStatsCard } from "../src/cards/stats-card.js"; +import { renderStatsCard } from "../../src/cards/stats-card.js"; import { clampValue, CONSTANTS, parseArray, parseBoolean, renderError, -} from "../src/common/utils.js"; +} from "../../src/common/utils.js"; export default async (req, res) => { const { From 8f63eaeef9b4ef179a95a3ddf4bdee7136cbfa9f Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sat, 14 Jan 2023 11:57:53 +0530 Subject: [PATCH 18/64] Update stats-card.js --- src/cards/stats-card.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/cards/stats-card.js b/src/cards/stats-card.js index 11f5e98cb7069..abd872238c430 100644 --- a/src/cards/stats-card.js +++ b/src/cards/stats-card.js @@ -97,8 +97,19 @@ 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 { - name = "GitHub User", totalStars = "2018", totalCommits = "29019", totalIssues = "203", @@ -132,14 +143,6 @@ 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: { From f02186908d4b62201c0b699d2776684e34b8260f Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sat, 14 Jan 2023 11:59:30 +0530 Subject: [PATCH 19/64] Update stats-card.js --- src/cards/stats-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cards/stats-card.js b/src/cards/stats-card.js index abd872238c430..fb3c3daeeca22 100644 --- a/src/cards/stats-card.js +++ b/src/cards/stats-card.js @@ -98,7 +98,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { disable_animations = false, } = options; - const name = stats.name || "GitHub User", + const name = stats.name || "GitHub User" const apostrophe = ["x", "s"].includes(name.slice(-1).toLocaleLowerCase()) ? "" From ffd927af6de05b43191dd089813eb870339baf8c Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sun, 15 Jan 2023 15:39:54 +0530 Subject: [PATCH 20/64] Update top-languages-card.js --- src/cards/top-languages-card.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cards/top-languages-card.js b/src/cards/top-languages-card.js index 602d1b811b5df..8d13c6ddd0adc 100644 --- a/src/cards/top-languages-card.js +++ b/src/cards/top-languages-card.js @@ -261,6 +261,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, @@ -272,17 +278,12 @@ const renderTopLanguages = (topLangs, options = {}) => { theme, layout, custom_title, - locale, langs_count = DEFAULT_LANGS_COUNT, border_radius, border_color, + title = i18n.t("langcard.title"), } = options; - const i18n = new I18n({ - locale, - translations: langCardLocales, - }); - const { langs, totalLanguageSize } = useLanguages( topLangs, hide, @@ -317,7 +318,7 @@ const renderTopLanguages = (topLangs, options = {}) => { const card = new Card({ customTitle: custom_title, - defaultTitle: i18n.t("langcard.title"), + defaultTitle: title, width, height, border_radius, From 22aa6887f9503d1eb05a4af91c5654496dc6f6ef Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sun, 15 Jan 2023 15:43:28 +0530 Subject: [PATCH 21/64] Update index.js --- api/wild/index.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/api/wild/index.js b/api/wild/index.js index a42a22edf1c18..f0c2b946a84ab 100644 --- a/api/wild/index.js +++ b/api/wild/index.js @@ -24,7 +24,6 @@ export default async (req, res) => { bg_color, theme, cache_seconds, - custom_title, disable_animations, border_radius, border_color, @@ -33,20 +32,20 @@ export default async (req, res) => { try { const stats = { - totalStars: req.query.totalStars, - totalCommits: req.query.totalCommits, - totalIssues: req.query.totalIssues, - totalPRs: req.query.totalPRs, - contributedTo: req.query.contributedTo, + totalStars: req.query.total_stars, + totalCommits: req.query.total_commits, + totalIssues: req.query.total_issues, + totalPRs: req.query.total_prs, + contributedTo: req.query.total_contribs, rank: { level: req.query.level || 'S', score: req.query.score || 10 }, - starsTitle: req.query.starsTitle, - commitsTitle: req.query.commitsTitle, - issuesTitle: req.query.issuesTitle, - PRsTitle: req.query.PRsTitle, - contribsTitle: req.query.contribsTitle, + starsTitle: req.query.stars_title, + commitsTitle: req.query.commits_title, + issuesTitle: req.query.issues_title, + PRsTitle: req.query.prs_title, + contribsTitle: req.query.contribs_title, title: req.query.title, }; @@ -79,7 +78,6 @@ export default async (req, res) => { text_bold: parseBoolean(text_bold), bg_color, theme, - custom_title, border_radius, border_color, disable_animations: parseBoolean(disable_animations), From 5448a611ba0508309362ed9db4a9698ea2915b2a Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sun, 15 Jan 2023 15:47:18 +0530 Subject: [PATCH 22/64] Create top-langs.js --- api/wild/top-langs.js | 67 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 api/wild/top-langs.js diff --git a/api/wild/top-langs.js b/api/wild/top-langs.js new file mode 100644 index 0000000000000..731752b71cf21 --- /dev/null +++ b/api/wild/top-langs.js @@ -0,0 +1,67 @@ +import { renderTopLanguages } from "../src/cards/top-languages-card.js"; +import { + clampValue, + CONSTANTS, + parseArray, + parseBoolean, + renderError, +} from "../src/common/utils.js"; + +export default async (req, res) => { + const { + hide, + hide_title, + hide_border, + card_width, + title_color, + text_color, + bg_color, + theme, + cache_seconds, + layout, + exclude_repo, + custom_title, + locale, + border_radius, + border_color, + } = req.query; + res.setHeader("Content-Type", "image/svg+xml"); + + try { + const topLangs = req.query.top_langs.split(","); + + const cacheSeconds = clampValue( + parseInt(cache_seconds || CONSTANTS.FOUR_HOURS, 10), + CONSTANTS.FOUR_HOURS, + CONSTANTS.ONE_DAY, + ); + + res.setHeader( + "Cache-Control", + `max-age=${ + cacheSeconds / 2 + }, s-maxage=${cacheSeconds}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`, + ); + + return res.send( + renderTopLanguages(topLangs, { + hide_title: parseBoolean(hide_title), + hide_border: parseBoolean(hide_border), + card_width: parseInt(card_width, 10), + hide: parseArray(hide), + title_color, + text_color, + bg_color, + theme, + layout, + langs_count: topLangs.length, + border_radius, + border_color, + locale: locale ? locale.toLowerCase() : null, + }), + ); + } catch (err) { + res.setHeader("Cache-Control", `no-cache, no-store, must-revalidate`); // Don't cache error responses. + return res.send(renderError(err.message, err.secondaryMessage)); + } +}; From c6ca64551ec123b60771fc249d8ddf7a3f2c6bdd Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sun, 15 Jan 2023 15:49:01 +0530 Subject: [PATCH 23/64] Update top-langs.js --- api/wild/top-langs.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/wild/top-langs.js b/api/wild/top-langs.js index 731752b71cf21..50fc5fb71aa13 100644 --- a/api/wild/top-langs.js +++ b/api/wild/top-langs.js @@ -1,11 +1,11 @@ -import { renderTopLanguages } from "../src/cards/top-languages-card.js"; +import { renderTopLanguages } from "../../src/cards/top-languages-card.js"; import { clampValue, CONSTANTS, parseArray, parseBoolean, renderError, -} from "../src/common/utils.js"; +} from "../../src/common/utils.js"; export default async (req, res) => { const { From ede2574b13407b107797591bf66a50d264282c17 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sun, 15 Jan 2023 15:55:48 +0530 Subject: [PATCH 24/64] Update top-langs.js --- api/wild/top-langs.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/api/wild/top-langs.js b/api/wild/top-langs.js index 50fc5fb71aa13..fa4b1262a4d54 100644 --- a/api/wild/top-langs.js +++ b/api/wild/top-langs.js @@ -28,7 +28,24 @@ export default async (req, res) => { res.setHeader("Content-Type", "image/svg+xml"); try { - const topLangs = req.query.top_langs.split(","); + const topLangs = req.query.top_langs.split(",") || [ + { + name: "Javascript", + size: 50, + color: "#4287f5", + }, + { + name: "Python", + size: 30, + color: "#eb4034", + }, + { + name: "Ruby", + size: 20, + color: "#32a852", + } + ]; + const title = req.query.title || "Most Used Languages"; const cacheSeconds = clampValue( parseInt(cache_seconds || CONSTANTS.FOUR_HOURS, 10), @@ -58,6 +75,7 @@ export default async (req, res) => { border_radius, border_color, locale: locale ? locale.toLowerCase() : null, + title, }), ); } catch (err) { From 6738c6db5f89f578a8ce0a5e02e160ad5291f51a Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sun, 15 Jan 2023 15:57:10 +0530 Subject: [PATCH 25/64] Update top-langs.js --- api/wild/top-langs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/wild/top-langs.js b/api/wild/top-langs.js index fa4b1262a4d54..a1c9a2e584394 100644 --- a/api/wild/top-langs.js +++ b/api/wild/top-langs.js @@ -28,7 +28,7 @@ export default async (req, res) => { res.setHeader("Content-Type", "image/svg+xml"); try { - const topLangs = req.query.top_langs.split(",") || [ + const topLangs = req.query.top_langs ? req.query.top_langs.split(",") : [ { name: "Javascript", size: 50, From cc558e4d7c938631870a1a167068829a7ef15ade Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sun, 15 Jan 2023 16:01:17 +0530 Subject: [PATCH 26/64] Update top-langs.js --- api/wild/top-langs.js | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/api/wild/top-langs.js b/api/wild/top-langs.js index a1c9a2e584394..3092b619f6bc4 100644 --- a/api/wild/top-langs.js +++ b/api/wild/top-langs.js @@ -28,23 +28,32 @@ export default async (req, res) => { res.setHeader("Content-Type", "image/svg+xml"); try { - const topLangs = req.query.top_langs ? req.query.top_langs.split(",") : [ - { - name: "Javascript", - size: 50, - color: "#4287f5", - }, - { - name: "Python", - size: 30, - color: "#eb4034", - }, - { - name: "Ruby", - size: 20, - color: "#32a852", - } - ]; + let topLangs = [] + if (req.query.top_langs) { + const split = req.query.top_langs.split(","); + split.forEach(lang => { + topLangs.push(JSON.parse(lang)) + }); + } else { + topLangs = [ + { + name: "Javascript", + size: 50, + color: "#4287f5", + }, + { + name: "Python", + size: 30, + color: "#eb4034", + }, + { + name: "Ruby", + size: 20, + color: "#32a852", + } + ]; + } + const title = req.query.title || "Most Used Languages"; const cacheSeconds = clampValue( From 114225e72ee9b250c8181112571294fe1cf4585d Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Sun, 15 Jan 2023 16:04:55 +0530 Subject: [PATCH 27/64] Update top-langs.js --- api/wild/top-langs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/wild/top-langs.js b/api/wild/top-langs.js index 3092b619f6bc4..06aedc1136c31 100644 --- a/api/wild/top-langs.js +++ b/api/wild/top-langs.js @@ -30,7 +30,7 @@ export default async (req, res) => { try { let topLangs = [] if (req.query.top_langs) { - const split = req.query.top_langs.split(","); + const split = req.query.top_langs.split(";"); split.forEach(lang => { topLangs.push(JSON.parse(lang)) }); From 2a1d255e45bcb198cbbdff2f81b4765c0ba740d4 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Mon, 16 Jan 2023 15:12:05 +0530 Subject: [PATCH 28/64] Update top-langs.js --- api/wild/top-langs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/wild/top-langs.js b/api/wild/top-langs.js index 06aedc1136c31..1eefbed835718 100644 --- a/api/wild/top-langs.js +++ b/api/wild/top-langs.js @@ -32,7 +32,7 @@ export default async (req, res) => { if (req.query.top_langs) { const split = req.query.top_langs.split(";"); split.forEach(lang => { - topLangs.push(JSON.parse(lang)) + topLangs.push(JSON.parse(decodeURIComponent(lang))) }); } else { topLangs = [ From 642d63d4f00d1879b94e2eb636e24314c57e574e Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Mon, 16 Jan 2023 15:23:20 +0530 Subject: [PATCH 29/64] Update top-langs.js --- api/wild/top-langs.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/wild/top-langs.js b/api/wild/top-langs.js index 1eefbed835718..4b9b381f114ec 100644 --- a/api/wild/top-langs.js +++ b/api/wild/top-langs.js @@ -29,8 +29,8 @@ export default async (req, res) => { try { let topLangs = [] - if (req.query.top_langs) { - const split = req.query.top_langs.split(";"); + if (req.query.langs) { + const split = req.query.langs.split(";"); split.forEach(lang => { topLangs.push(JSON.parse(decodeURIComponent(lang))) }); From 1689ca6febf827ed6e1c0ee7561da3faa0ea1fb7 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Mon, 16 Jan 2023 15:31:04 +0530 Subject: [PATCH 30/64] Update top-langs.js --- api/wild/top-langs.js | 1 - 1 file changed, 1 deletion(-) diff --git a/api/wild/top-langs.js b/api/wild/top-langs.js index 4b9b381f114ec..da9657827b204 100644 --- a/api/wild/top-langs.js +++ b/api/wild/top-langs.js @@ -9,7 +9,6 @@ import { export default async (req, res) => { const { - hide, hide_title, hide_border, card_width, From af36d0b2e1a03b34cdf314b2f297165c27212b5f Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Mon, 16 Jan 2023 15:32:22 +0530 Subject: [PATCH 31/64] Update top-langs.js --- api/wild/top-langs.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/api/wild/top-langs.js b/api/wild/top-langs.js index da9657827b204..98a0cada1631c 100644 --- a/api/wild/top-langs.js +++ b/api/wild/top-langs.js @@ -18,9 +18,6 @@ export default async (req, res) => { theme, cache_seconds, layout, - exclude_repo, - custom_title, - locale, border_radius, border_color, } = req.query; From 9c08efedbf719769bae1f775a847b8c83aa358e8 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Mon, 16 Jan 2023 15:37:02 +0530 Subject: [PATCH 32/64] Update top-langs.js --- api/wild/top-langs.js | 1 - 1 file changed, 1 deletion(-) diff --git a/api/wild/top-langs.js b/api/wild/top-langs.js index 98a0cada1631c..18c690d363de8 100644 --- a/api/wild/top-langs.js +++ b/api/wild/top-langs.js @@ -70,7 +70,6 @@ export default async (req, res) => { hide_title: parseBoolean(hide_title), hide_border: parseBoolean(hide_border), card_width: parseInt(card_width, 10), - hide: parseArray(hide), title_color, text_color, bg_color, From 246671326141746852b3b1d649e5008e072814b3 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Mon, 16 Jan 2023 15:37:18 +0530 Subject: [PATCH 33/64] Update top-langs.js --- api/wild/top-langs.js | 1 - 1 file changed, 1 deletion(-) diff --git a/api/wild/top-langs.js b/api/wild/top-langs.js index 18c690d363de8..9afc13c455232 100644 --- a/api/wild/top-langs.js +++ b/api/wild/top-langs.js @@ -78,7 +78,6 @@ export default async (req, res) => { langs_count: topLangs.length, border_radius, border_color, - locale: locale ? locale.toLowerCase() : null, title, }), ); From 42503cf90c755f4ed2412c8979605bca1d6c6940 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Mon, 16 Jan 2023 15:43:03 +0530 Subject: [PATCH 34/64] Update top-langs.js --- api/wild/top-langs.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/api/wild/top-langs.js b/api/wild/top-langs.js index 9afc13c455232..9d106dedcdd14 100644 --- a/api/wild/top-langs.js +++ b/api/wild/top-langs.js @@ -28,7 +28,16 @@ export default async (req, res) => { if (req.query.langs) { const split = req.query.langs.split(";"); split.forEach(lang => { - topLangs.push(JSON.parse(decodeURIComponent(lang))) + let { + name = "No Name", + size = "0", + color, + } = JSON.parse(decodeURIComponent(lang)) + topLangs.push({ + name, + size, + color, + }); }); } else { topLangs = [ From 3cebd8907b9406e46ac80652290688fd40e0293c Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Mon, 16 Jan 2023 16:14:14 +0530 Subject: [PATCH 35/64] Update top-languages-card.js --- src/cards/top-languages-card.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cards/top-languages-card.js b/src/cards/top-languages-card.js index 8d13c6ddd0adc..25e24cdb9cbab 100644 --- a/src/cards/top-languages-card.js +++ b/src/cards/top-languages-card.js @@ -46,14 +46,14 @@ const getLongestLang = (arr) => * @param {string} props.progress Usage of the programming language in percentage. * @returns {string} Programming language SVG node. */ -const createProgressTextNode = ({ width, color, name, progress }) => { +const createProgressTextNode = ({ width, color, name, progress, text }) => { const paddingRight = 95; const progressTextX = width - paddingRight + 10; const progressWidth = width - paddingRight; return ` ${name} - ${progress}% + ${text || `${progress}%`} ${createProgressNode({ x: 0, y: 25, @@ -81,7 +81,7 @@ const createCompactLangNode = ({ lang, totalSize }) => { - ${lang.name} ${percentage}% + ${lang.name} ${lang.text || `${percentage}%`} `; @@ -117,7 +117,7 @@ const createLanguageTextNode = ({ langs, totalSize }) => { 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, @@ -140,6 +140,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, }); }), gap: 40, From 2cb4861b2487ca74ce5f2330611f7d338c5420a8 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Mon, 16 Jan 2023 16:14:59 +0530 Subject: [PATCH 36/64] Update top-langs.js --- api/wild/top-langs.js | 1 + 1 file changed, 1 insertion(+) diff --git a/api/wild/top-langs.js b/api/wild/top-langs.js index 9d106dedcdd14..2a8a9f1ef93fb 100644 --- a/api/wild/top-langs.js +++ b/api/wild/top-langs.js @@ -32,6 +32,7 @@ export default async (req, res) => { name = "No Name", size = "0", color, + text, } = JSON.parse(decodeURIComponent(lang)) topLangs.push({ name, From 0adcb158f96fef5e455a7a369497210902785245 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Mon, 16 Jan 2023 16:21:00 +0530 Subject: [PATCH 37/64] Update top-languages-card.js --- src/cards/top-languages-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cards/top-languages-card.js b/src/cards/top-languages-card.js index 25e24cdb9cbab..1c1c89f129bb7 100644 --- a/src/cards/top-languages-card.js +++ b/src/cards/top-languages-card.js @@ -117,7 +117,7 @@ const createLanguageTextNode = ({ langs, totalSize }) => { const percent = ((longestLang.size / totalSize) * 100).toFixed(2); const minGap = 150; - const maxGap = 20 + measureText(`${longestLang.name} ${longestLang.text || `${percent}%`}, 11); + const maxGap = 20 + measureText(`${longestLang.name} ${longestLang.text || `${percent}%`}`, 11); return flexLayout({ items: layouts, gap: maxGap < minGap ? minGap : maxGap, From 80e6d0acc5988b1b44cbb9f4ee98db3958d5e895 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Mon, 16 Jan 2023 16:26:44 +0530 Subject: [PATCH 38/64] Update top-languages-card.js --- src/cards/top-languages-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cards/top-languages-card.js b/src/cards/top-languages-card.js index 1c1c89f129bb7..d7b9cae4631fd 100644 --- a/src/cards/top-languages-card.js +++ b/src/cards/top-languages-card.js @@ -53,7 +53,7 @@ const createProgressTextNode = ({ width, color, name, progress, text }) => { return ` ${name} - ${text || `${progress}%`} + ${'test'} ${createProgressNode({ x: 0, y: 25, From 4ecebbca944959db7bef54e0a95bdb99570a83d7 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Mon, 16 Jan 2023 16:28:51 +0530 Subject: [PATCH 39/64] Update top-languages-card.js --- src/cards/top-languages-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cards/top-languages-card.js b/src/cards/top-languages-card.js index d7b9cae4631fd..e4ade709bfe6f 100644 --- a/src/cards/top-languages-card.js +++ b/src/cards/top-languages-card.js @@ -53,7 +53,7 @@ const createProgressTextNode = ({ width, color, name, progress, text }) => { return ` ${name} - ${'test'} + ${text} ${createProgressNode({ x: 0, y: 25, From df42981d3469ec6542edc21a4cdb20084c4bd160 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Mon, 16 Jan 2023 16:34:14 +0530 Subject: [PATCH 40/64] Update top-langs.js --- api/wild/top-langs.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/wild/top-langs.js b/api/wild/top-langs.js index 2a8a9f1ef93fb..f8da1a5d50b40 100644 --- a/api/wild/top-langs.js +++ b/api/wild/top-langs.js @@ -33,11 +33,12 @@ export default async (req, res) => { size = "0", color, text, - } = JSON.parse(decodeURIComponent(lang)) + } = JSON.parse(lang) topLangs.push({ name, size, color, + text, }); }); } else { From 27029cd565507312fc851fc7e53da2d0e843ab49 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Mon, 16 Jan 2023 16:35:32 +0530 Subject: [PATCH 41/64] Update top-languages-card.js --- src/cards/top-languages-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cards/top-languages-card.js b/src/cards/top-languages-card.js index e4ade709bfe6f..a00ae8ef4dd63 100644 --- a/src/cards/top-languages-card.js +++ b/src/cards/top-languages-card.js @@ -53,7 +53,7 @@ const createProgressTextNode = ({ width, color, name, progress, text }) => { return ` ${name} - ${text} + ${lang.text || `${percentage}%`} ${createProgressNode({ x: 0, y: 25, From 5675ce77b175616932283518a10ce36691383891 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Mon, 16 Jan 2023 16:37:25 +0530 Subject: [PATCH 42/64] Update top-langs.js --- api/wild/top-langs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/wild/top-langs.js b/api/wild/top-langs.js index f8da1a5d50b40..1907a180586dc 100644 --- a/api/wild/top-langs.js +++ b/api/wild/top-langs.js @@ -37,7 +37,7 @@ export default async (req, res) => { topLangs.push({ name, size, - color, + color: `#${color}`, text, }); }); From b320054e90ee4d1c356e97f53270075220dc5d9c Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Mon, 16 Jan 2023 16:38:33 +0530 Subject: [PATCH 43/64] Update top-languages-card.js --- src/cards/top-languages-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cards/top-languages-card.js b/src/cards/top-languages-card.js index a00ae8ef4dd63..0659ee138f629 100644 --- a/src/cards/top-languages-card.js +++ b/src/cards/top-languages-card.js @@ -53,7 +53,7 @@ const createProgressTextNode = ({ width, color, name, progress, text }) => { return ` ${name} - ${lang.text || `${percentage}%`} + ${text || `${percentage}%`} ${createProgressNode({ x: 0, y: 25, From 2770161e33074a66d153b99c1faa2402f7087c26 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Mon, 16 Jan 2023 16:40:12 +0530 Subject: [PATCH 44/64] Update top-languages-card.js --- src/cards/top-languages-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cards/top-languages-card.js b/src/cards/top-languages-card.js index 0659ee138f629..1c1c89f129bb7 100644 --- a/src/cards/top-languages-card.js +++ b/src/cards/top-languages-card.js @@ -53,7 +53,7 @@ const createProgressTextNode = ({ width, color, name, progress, text }) => { return ` ${name} - ${text || `${percentage}%`} + ${text || `${progress}%`} ${createProgressNode({ x: 0, y: 25, From 01f726c3163402ce0f98bd18fef49374f5684490 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Tue, 17 Jan 2023 15:43:37 +0530 Subject: [PATCH 45/64] Update repo-card.js --- src/cards/repo-card.js | 46 ++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/cards/repo-card.js b/src/cards/repo-card.js index a306c1d56a561..1c86b8d234c6a 100644 --- a/src/cards/repo-card.js +++ b/src/cards/repo-card.js @@ -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,29 @@ const renderRepoCard = (repo, options = {}) => { border_color, locale, } = options; + + const i18n = new I18n({ + locale, + translations: repoCardLocales, + }); + + const { + name, + nameWithOwner, + description, + primaryLanguage, + isArchived, + isTemplate, + starCount, + forkCount, + highlight = isTemplate + ? // @ts-ignore + getBadgeSVG(i18n.t("repocard.template"), colors.textColor) + : isArchived + ? // @ts-ignore + getBadgeSVG(i18n.t("repocard.archived"), colors.textColor) + : "", + } = repo; const lineHeight = 10; const header = show_owner ? nameWithOwner : name; @@ -125,11 +138,6 @@ 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, @@ -181,13 +189,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 } From c1e2858330a03f140fb0b3e8152f485928056e98 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Tue, 17 Jan 2023 15:47:39 +0530 Subject: [PATCH 46/64] Update repo-card.js --- src/cards/repo-card.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/cards/repo-card.js b/src/cards/repo-card.js index 1c86b8d234c6a..8d63f889d98e1 100644 --- a/src/cards/repo-card.js +++ b/src/cards/repo-card.js @@ -151,9 +151,20 @@ const renderRepoCard = (repo, options = {}) => { 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"); From 866e509d078a1bb0d127231d7c9a34a67cc2da78 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Tue, 17 Jan 2023 15:49:21 +0530 Subject: [PATCH 47/64] Create pin.js --- api/wild/pin.js | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 api/wild/pin.js diff --git a/api/wild/pin.js b/api/wild/pin.js new file mode 100644 index 0000000000000..c1ccc610c0ac4 --- /dev/null +++ b/api/wild/pin.js @@ -0,0 +1,81 @@ +import { renderRepoCard } from "../src/cards/repo-card.js"; +import { + clampValue, + CONSTANTS, + parseBoolean, + renderError, +} from "../src/common/utils.js"; + +export default async (req, res) => { + const { + hide_border, + title_color, + icon_color, + text_color, + bg_color, + theme, + cache_seconds, + border_radius, + border_color, + } = req.query; + + res.setHeader("Content-Type", "image/svg+xml"); + + try { + const repoData = { + name: req.query.title, + description: req.query.description, + primaryLanguage: { + name: req.query.footer, + color: `#${req.query.badge}`, + }, + starCount: req.query.stars, + forkCount: req.query.forks, + highlight: req.query.highlight, + }; + + let cacheSeconds = clampValue( + parseInt(cache_seconds || CONSTANTS.FOUR_HOURS, 10), + CONSTANTS.FOUR_HOURS, + CONSTANTS.ONE_DAY, + ); + + /* + if star count & fork count is over 1k then we are kFormating the text + and if both are zero we are not showing the stats + so we can just make the cache longer, since there is no need to frequent updates + */ + const stars = repoData.starCount; + const forks = repoData.forkCount; + if (!isNaN(stars) && !isNaN(forks)) { + const isBothOver1K = stars > 1000 && forks > 1000; + const isBothUnder1 = stars < 1 && forks < 1; + if (!cache_seconds && (isBothOver1K || isBothUnder1)) { + cacheSeconds = CONSTANTS.FOUR_HOURS; + } + } + + res.setHeader( + "Cache-Control", + `max-age=${ + cacheSeconds / 2 + }, s-maxage=${cacheSeconds}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`, + ); + + return res.send( + renderRepoCard(repoData, { + hide_border: parseBoolean(hide_border), + title_color, + icon_color, + text_color, + bg_color, + theme, + border_radius, + border_color, + }), + ); + } catch (err) { + res.setHeader("Cache-Control", `no-cache, no-store, must-revalidate`); // Don't cache error responses. + return res.send(renderError(err.message, err.secondaryMessage)); + } +}; From b8425d36c8e9b8b1539015b21408842cec733d84 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Tue, 17 Jan 2023 15:51:33 +0530 Subject: [PATCH 48/64] Update repo-card.js --- src/cards/repo-card.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/cards/repo-card.js b/src/cards/repo-card.js index 8d63f889d98e1..64a53a4087a2f 100644 --- a/src/cards/repo-card.js +++ b/src/cards/repo-card.js @@ -105,6 +105,15 @@ const renderRepoCard = (repo, options = {}) => { translations: repoCardLocales, }); + const colors = getCardColors({ + title_color, + icon_color, + text_color, + bg_color, + border_color, + theme, + }); + const { name, nameWithOwner, @@ -139,14 +148,6 @@ const renderRepoCard = (repo, options = {}) => { (descriptionLines > 1 ? 120 : 110) + descriptionLines * lineHeight; // 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) From bf0a15f94ff85d500cce8568bedab1c72a89039e Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Tue, 17 Jan 2023 15:52:46 +0530 Subject: [PATCH 49/64] Update pin.js --- api/wild/pin.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/api/wild/pin.js b/api/wild/pin.js index c1ccc610c0ac4..e1375b4e19cf2 100644 --- a/api/wild/pin.js +++ b/api/wild/pin.js @@ -1,10 +1,10 @@ -import { renderRepoCard } from "../src/cards/repo-card.js"; +import { renderRepoCard } from "../../src/cards/repo-card.js"; import { clampValue, CONSTANTS, parseBoolean, renderError, -} from "../src/common/utils.js"; +} from "../../src/common/utils.js"; export default async (req, res) => { const { @@ -23,15 +23,15 @@ export default async (req, res) => { try { const repoData = { - name: req.query.title, - description: req.query.description, + name: req.query.title || "awesome/repo", + description: req.query.description || "What an awesome repo!", primaryLanguage: { - name: req.query.footer, - color: `#${req.query.badge}`, + name: req.query.footer || "Awesome", + color: `#${req.query.badge}` || "#4287f5", }, - starCount: req.query.stars, - forkCount: req.query.forks, - highlight: req.query.highlight, + starCount: req.query.stars || 12838, + forkCount: req.query.forks || 8929, + highlight: req.query.highlight || "😎", }; let cacheSeconds = clampValue( From 05b611ad58114c16f89d7b714175579244104315 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Tue, 17 Jan 2023 15:55:42 +0530 Subject: [PATCH 50/64] Update pin.js --- api/wild/pin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/wild/pin.js b/api/wild/pin.js index e1375b4e19cf2..faa5987d8822e 100644 --- a/api/wild/pin.js +++ b/api/wild/pin.js @@ -31,7 +31,7 @@ export default async (req, res) => { }, starCount: req.query.stars || 12838, forkCount: req.query.forks || 8929, - highlight: req.query.highlight || "😎", + highlight: req.query.highlight || "AWESOME", }; let cacheSeconds = clampValue( From 589badc4832bc997e7a07a0c995c9663e3139447 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Tue, 17 Jan 2023 15:57:59 +0530 Subject: [PATCH 51/64] Update pin.js --- api/wild/pin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/wild/pin.js b/api/wild/pin.js index faa5987d8822e..2daeb91b94fbf 100644 --- a/api/wild/pin.js +++ b/api/wild/pin.js @@ -27,7 +27,7 @@ export default async (req, res) => { description: req.query.description || "What an awesome repo!", primaryLanguage: { name: req.query.footer || "Awesome", - color: `#${req.query.badge}` || "#4287f5", + color: req.query.badge ? `#${req.query.badge}` : "#4287f5", }, starCount: req.query.stars || 12838, forkCount: req.query.forks || 8929, From c33f3f617a4b023eac3844e65aa78fc6729623f7 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Tue, 17 Jan 2023 15:59:11 +0530 Subject: [PATCH 52/64] Update repo-card.js --- src/cards/repo-card.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cards/repo-card.js b/src/cards/repo-card.js index 64a53a4087a2f..7fcf5953ed5c6 100644 --- a/src/cards/repo-card.js +++ b/src/cards/repo-card.js @@ -200,9 +200,7 @@ const renderRepoCard = (repo, options = {}) => { `); return card.render(` - ${ - highlight - } + ${highlight} ${descriptionSvg} From 04ed2bdd3fa749b1c6339c4daf5b22a88605d82b Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Tue, 17 Jan 2023 16:02:23 +0530 Subject: [PATCH 53/64] Update repo-card.js --- src/cards/repo-card.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cards/repo-card.js b/src/cards/repo-card.js index 7fcf5953ed5c6..3a20a93dca2c5 100644 --- a/src/cards/repo-card.js +++ b/src/cards/repo-card.js @@ -123,14 +123,18 @@ const renderRepoCard = (repo, options = {}) => { isTemplate, starCount, forkCount, + highlight, + } = repo; + + if (!highlight) { highlight = isTemplate ? // @ts-ignore getBadgeSVG(i18n.t("repocard.template"), colors.textColor) : isArchived ? // @ts-ignore getBadgeSVG(i18n.t("repocard.archived"), colors.textColor) - : "", - } = repo; + : "" + } const lineHeight = 10; const header = show_owner ? nameWithOwner : name; From e245941e5a91893e18b12ce3a1bbc8d3d9db6106 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Tue, 17 Jan 2023 16:05:24 +0530 Subject: [PATCH 54/64] Update repo-card.js --- src/cards/repo-card.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cards/repo-card.js b/src/cards/repo-card.js index 3a20a93dca2c5..e32a8d0213b75 100644 --- a/src/cards/repo-card.js +++ b/src/cards/repo-card.js @@ -134,6 +134,8 @@ const renderRepoCard = (repo, options = {}) => { ? // @ts-ignore getBadgeSVG(i18n.t("repocard.archived"), colors.textColor) : "" + } else { + highlight = getBadgeSVG(highlight); } const lineHeight = 10; From 55a3cecd4999989dcc3e0dc5a30d03e2293e3814 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Tue, 17 Jan 2023 16:07:42 +0530 Subject: [PATCH 55/64] Update repo-card.js --- src/cards/repo-card.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/cards/repo-card.js b/src/cards/repo-card.js index e32a8d0213b75..7079073cb16db 100644 --- a/src/cards/repo-card.js +++ b/src/cards/repo-card.js @@ -123,20 +123,18 @@ const renderRepoCard = (repo, options = {}) => { isTemplate, starCount, forkCount, - highlight, } = repo; - if (!highlight) { - highlight = isTemplate + const highlight = repo.highlight + ? // @ts-ignore + getBadgeSVG(repo.highlight) + : isTemplate ? // @ts-ignore getBadgeSVG(i18n.t("repocard.template"), colors.textColor) : isArchived ? // @ts-ignore getBadgeSVG(i18n.t("repocard.archived"), colors.textColor) : "" - } else { - highlight = getBadgeSVG(highlight); - } const lineHeight = 10; const header = show_owner ? nameWithOwner : name; From 97cef21e4eeffd997f7afaf3d0443a94a4b6bd09 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Tue, 17 Jan 2023 16:09:08 +0530 Subject: [PATCH 56/64] Update repo-card.js --- src/cards/repo-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cards/repo-card.js b/src/cards/repo-card.js index 7079073cb16db..1cf1de6603ad2 100644 --- a/src/cards/repo-card.js +++ b/src/cards/repo-card.js @@ -127,7 +127,7 @@ const renderRepoCard = (repo, options = {}) => { const highlight = repo.highlight ? // @ts-ignore - getBadgeSVG(repo.highlight) + getBadgeSVG(repo.highlight, colors.textColor) : isTemplate ? // @ts-ignore getBadgeSVG(i18n.t("repocard.template"), colors.textColor) From 6243c702c32a1639494f4fd6202a87bbe6ff8822 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Tue, 17 Jan 2023 16:33:50 +0530 Subject: [PATCH 57/64] Update top-langs.js --- api/wild/top-langs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/wild/top-langs.js b/api/wild/top-langs.js index 1907a180586dc..1c908267406af 100644 --- a/api/wild/top-langs.js +++ b/api/wild/top-langs.js @@ -37,7 +37,7 @@ export default async (req, res) => { topLangs.push({ name, size, - color: `#${color}`, + color: color ? `#${color}` : undefined, text, }); }); From 9829ab990d6b5f0b28b2fc83817b069f50e47b54 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Tue, 17 Jan 2023 16:47:22 +0530 Subject: [PATCH 58/64] Update readme.md --- readme.md | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/readme.md b/readme.md index bfe042fcc2032..7108a8f9c2276 100644 --- a/readme.md +++ b/readme.md @@ -92,6 +92,7 @@ Visit and make a small donation to hel - [Repo Card Exclusive Options](#repo-card-exclusive-options) - [Language Card Exclusive Options](#language-card-exclusive-options) - [Wakatime Card Exclusive Option](#wakatime-card-exclusive-options) +- [Wild Cards](#wild-cards) - [Deploy Yourself](#deploy-on-your-own-vercel-instance) - [Keep your fork up to date](#keep-your-fork-up-to-date) @@ -495,6 +496,64 @@ By default, GitHub does not lay out the cards side by side. To do that, you can ``` +## Wild Cards +You can also generate custom cards with custom text and custom values (these do not show any GitHub statistics - they're custom values that you provide): +

+ + + + +

+ +The wild/custom cards can be generated by using the `/api/wild/`, `/api/wild/top-langs/`, and `/api/wild/pin/` endpoints. The following parameters can be provided: + +### `/api/wild/` + + + +Additionally, the `score` parameter must be given a value from `0` to `100` where `100` doesn't fill the circle at all, and `0` fills the circle completely (the demo above has `score=90`). + +### `/api/wild/top-langs/` + + + +Here, the languages are defined using the `langs` parameter. It is of the following format (JSON with `;` separating the objects): +```json +{ + "name": "Category1", + "size": 60, + "color": "4287f5", + "text": "3 thousand" +}; +{ + "name": "Category2", + "size": 40, + "color": "fcba03", + "text": "3 thousand" +} +``` + +`name` is the name of the category. `size` is an arbitary size used to calculate percentages. This can be hours, percent, or any other unit you wish to use. `color` is the color of the category. `text` is what text to display next to the categry. If left blank, a percentage will be calculated and displayed. + +### `/api/wild/pin/` + + + +Here, the `badge` parameter was used to set the color of the small round icon (`4287f5`) was passed. + +Finally, here are some specifications that apply to all three endpoints. + +### All Three +Colors are passed as hex codes without the `#` character. For example, `ffffff`. This is the same as the main API. + +Parameters like `total_stars` and `forks` can accept both numbers and text. If a number is given, it will automatically be formatted to use k-notation for thousands. + +Parameters that apply only to the main API such as `username`, `repo`, `show_owner`, `locale, etc won't work for this API. Other parameters like `layout` and `text_color` ***will*** work. + +The new parameters that have been added are explained above (shown in the images). Parameters are lowercase snake-cased like for the main API. + +Finally, no parameter is required (yay!) :) If essential parameters like `total_stars` aren't given, random values will be used, which is not very useful, but this is so that no errors are formed! + ## Deploy on your own Vercel instance #### [Check Out Step By Step Video Tutorial By @codeSTACKr](https://youtu.be/n6d4KHSKqGk?t=107) From 03465922b095ad7161bfdbc7cfdae578a31e707f Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Tue, 17 Jan 2023 16:49:19 +0530 Subject: [PATCH 59/64] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 7108a8f9c2276..97b6f3f8b0f96 100644 --- a/readme.md +++ b/readme.md @@ -515,7 +515,7 @@ Additionally, the `score` parameter must be given a value from `0` to `100` wher ### `/api/wild/top-langs/` - + Here, the languages are defined using the `langs` parameter. It is of the following format (JSON with `;` separating the objects): ```json From 017e3ba180371040e38197343455ec3eabf4f481 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Tue, 17 Jan 2023 16:54:56 +0530 Subject: [PATCH 60/64] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 97b6f3f8b0f96..9606e552a3bf4 100644 --- a/readme.md +++ b/readme.md @@ -548,7 +548,7 @@ Colors are passed as hex codes without the `#` character. For example, `ffffff`. Parameters like `total_stars` and `forks` can accept both numbers and text. If a number is given, it will automatically be formatted to use k-notation for thousands. -Parameters that apply only to the main API such as `username`, `repo`, `show_owner`, `locale, etc won't work for this API. Other parameters like `layout` and `text_color` ***will*** work. +Parameters that apply only to the main API such as `username`, `repo`, `show_owner`, `locale`, etc won't work for this API. Other parameters like `layout` and `text_color` ***will*** work. The new parameters that have been added are explained above (shown in the images). Parameters are lowercase snake-cased like for the main API. From a885425b5234b5dc5bee9c70dd659ddecbe458b0 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Tue, 17 Jan 2023 17:07:41 +0530 Subject: [PATCH 61/64] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 9606e552a3bf4..37e3ecabb5369 100644 --- a/readme.md +++ b/readme.md @@ -552,7 +552,7 @@ Parameters that apply only to the main API such as `username`, `repo`, `show_own The new parameters that have been added are explained above (shown in the images). Parameters are lowercase snake-cased like for the main API. -Finally, no parameter is required (yay!) :) If essential parameters like `total_stars` aren't given, random values will be used, which is not very useful, but this is so that no errors are formed! +Finally, no parameter is required, and parameters that aren't given will default to the most sensible option (original titles, ambigous descriptions, theme-based colors, and fake numbers). ## Deploy on your own Vercel instance From 11cb8dffc1345d1f3747a59503f480390505e634 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Thu, 26 Jan 2023 16:51:40 +0530 Subject: [PATCH 62/64] Disable cache --- api/wild/index.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/api/wild/index.js b/api/wild/index.js index f0c2b946a84ab..092ccdd14d7c6 100644 --- a/api/wild/index.js +++ b/api/wild/index.js @@ -23,7 +23,6 @@ export default async (req, res) => { text_bold, bg_color, theme, - cache_seconds, disable_animations, border_radius, border_color, @@ -49,19 +48,6 @@ export default async (req, res) => { title: req.query.title, }; - const cacheSeconds = clampValue( - parseInt(cache_seconds || CONSTANTS.FOUR_HOURS, 10), - CONSTANTS.FOUR_HOURS, - CONSTANTS.ONE_DAY, - ); - - res.setHeader( - "Cache-Control", - `max-age=${ - cacheSeconds / 2 - }, s-maxage=${cacheSeconds}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`, - ); - return res.send( renderStatsCard(stats, { hide: parseArray(hide), @@ -84,7 +70,6 @@ export default async (req, res) => { }), ); } catch (err) { - res.setHeader("Cache-Control", `no-cache, no-store, must-revalidate`); // Don't cache error responses. return res.send(renderError(err.message, err.secondaryMessage)); } }; From 20914797b0d780485a8f13d762042b3c8e254b55 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Thu, 26 Jan 2023 16:52:18 +0530 Subject: [PATCH 63/64] Disable cache --- api/wild/pin.js | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/api/wild/pin.js b/api/wild/pin.js index 2daeb91b94fbf..cb5c244b7542d 100644 --- a/api/wild/pin.js +++ b/api/wild/pin.js @@ -14,7 +14,6 @@ export default async (req, res) => { text_color, bg_color, theme, - cache_seconds, border_radius, border_color, } = req.query; @@ -34,34 +33,6 @@ export default async (req, res) => { highlight: req.query.highlight || "AWESOME", }; - let cacheSeconds = clampValue( - parseInt(cache_seconds || CONSTANTS.FOUR_HOURS, 10), - CONSTANTS.FOUR_HOURS, - CONSTANTS.ONE_DAY, - ); - - /* - if star count & fork count is over 1k then we are kFormating the text - and if both are zero we are not showing the stats - so we can just make the cache longer, since there is no need to frequent updates - */ - const stars = repoData.starCount; - const forks = repoData.forkCount; - if (!isNaN(stars) && !isNaN(forks)) { - const isBothOver1K = stars > 1000 && forks > 1000; - const isBothUnder1 = stars < 1 && forks < 1; - if (!cache_seconds && (isBothOver1K || isBothUnder1)) { - cacheSeconds = CONSTANTS.FOUR_HOURS; - } - } - - res.setHeader( - "Cache-Control", - `max-age=${ - cacheSeconds / 2 - }, s-maxage=${cacheSeconds}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`, - ); - return res.send( renderRepoCard(repoData, { hide_border: parseBoolean(hide_border), @@ -75,7 +46,6 @@ export default async (req, res) => { }), ); } catch (err) { - res.setHeader("Cache-Control", `no-cache, no-store, must-revalidate`); // Don't cache error responses. return res.send(renderError(err.message, err.secondaryMessage)); } }; From a5114d12d0dc7c6f603699af56818c699fe048b1 Mon Sep 17 00:00:00 2001 From: Zohan Subhash Date: Thu, 26 Jan 2023 16:52:36 +0530 Subject: [PATCH 64/64] Update top-langs.js --- api/wild/top-langs.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/api/wild/top-langs.js b/api/wild/top-langs.js index 1c908267406af..8fefa0e1026a8 100644 --- a/api/wild/top-langs.js +++ b/api/wild/top-langs.js @@ -16,7 +16,6 @@ export default async (req, res) => { text_color, bg_color, theme, - cache_seconds, layout, border_radius, border_color, @@ -63,19 +62,6 @@ export default async (req, res) => { const title = req.query.title || "Most Used Languages"; - const cacheSeconds = clampValue( - parseInt(cache_seconds || CONSTANTS.FOUR_HOURS, 10), - CONSTANTS.FOUR_HOURS, - CONSTANTS.ONE_DAY, - ); - - res.setHeader( - "Cache-Control", - `max-age=${ - cacheSeconds / 2 - }, s-maxage=${cacheSeconds}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`, - ); - return res.send( renderTopLanguages(topLangs, { hide_title: parseBoolean(hide_title), @@ -93,7 +79,6 @@ export default async (req, res) => { }), ); } catch (err) { - res.setHeader("Cache-Control", `no-cache, no-store, must-revalidate`); // Don't cache error responses. return res.send(renderError(err.message, err.secondaryMessage)); } };