From 1e2131b19b89adc9062cbcfc39bb8ce47eaeb463 Mon Sep 17 00:00:00 2001 From: rjoydip Date: Thu, 6 Aug 2020 15:44:57 +0530 Subject: [PATCH] log changed as per request --- api/index.js | 4 ++-- readme.md | 12 ++++++++---- src/cards/stats-card.js | 18 +++++++----------- tests/renderStatsCard.test.js | 6 +++--- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/api/index.js b/api/index.js index 74d26ade..9cb9f6f0 100644 --- a/api/index.js +++ b/api/index.js @@ -13,11 +13,11 @@ module.exports = async (req, res) => { const { username, hide, + show_stats, hide_title, hide_border, hide_rank, show_icons, - show_forks, count_private, include_all_commits, line_height, @@ -58,11 +58,11 @@ module.exports = async (req, res) => { res.send( renderStatsCard(stats, { hide: parseArray(hide), + show_stats: parseArray(show_stats), show_icons: parseBoolean(show_icons), hide_title: parseBoolean(hide_title), hide_border: parseBoolean(hide_border), hide_rank: parseBoolean(hide_rank), - show_forks: parseBoolean(show_forks), include_all_commits: parseBoolean(include_all_commits), line_height, title_color, diff --git a/readme.md b/readme.md index e763aff2..624f5ef0 100644 --- a/readme.md +++ b/readme.md @@ -70,7 +70,7 @@ _Note: Ranks are calculated based on user's stats, see [src/calculateRank.js](./ ### Hiding individual stats -To hide any specific stats, you can pass a query parameter `?hide=` with comma separated values. +To hide any specific stats, you can pass a query parameter `hide=` with comma separated values. > Options: `&hide=stars,commits,prs,issues,contribs` @@ -78,14 +78,18 @@ To hide any specific stats, you can pass a query parameter `?hide=` with comma s ![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=contribs,prs) ``` -### Show total forked repository count +### Showing individual stats -To show forked repository count, you can pass a query parameter `show_forks=true`. +To hide any specific stats, you can pass a query parameter `show_stats=` with comma separated values. + +> Options: `&show_stats=stars,commits,prs,issues,contribs` ```md -![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_forks=true) +![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_stats=forks) ``` +Note: `show_stats` is more prioritize than `hide`. That means if you add `prs` in both `&hide=prs` and `show_stats=prs` then pull request status will display. + ### Adding private contributions count to total commits count You can add the count of all your private contributions to the total commits count by using the query parameter `?count_private=true`. diff --git a/src/cards/stats-card.js b/src/cards/stats-card.js index d772f174..01797648 100644 --- a/src/cards/stats-card.js +++ b/src/cards/stats-card.js @@ -55,12 +55,12 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { } = stats; const { hide = [], + show_stats = [], show_icons = false, hide_title = false, hide_border = false, hide_rank = false, include_all_commits = false, - show_forks = false, line_height = 25, title_color, icon_color, @@ -69,6 +69,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { theme = "default", } = options; + const new_hide = hide.concat(["forks"]); const lheight = parseInt(line_height, 10); // returns theme based colors with proper overrides and defaults @@ -87,7 +88,6 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { label: "Total Stars", value: totalStars, id: "stars", - isShowEnable: true, }, commits: { icon: icons.commits, @@ -96,45 +96,41 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { }`, value: totalCommits, id: "commits", - isShowEnable: true, }, prs: { icon: icons.prs, label: "Total PRs", value: totalPRs, id: "prs", - isShowEnable: true, }, issues: { icon: icons.issues, label: "Total Issues", value: totalIssues, id: "issues", - isShowEnable: true, }, contribs: { icon: icons.contribs, label: "Contributed to", value: contributedTo, id: "contribs", - isShowEnable: true, }, forks: { icon: icons.fork, label: "Total Forks", value: totalForkRepositories, id: "forks", - isShowEnable: show_forks, }, }; // filter out hidden stats defined by user & create the text nodes - const statItems = Object.entries(STATS) - .filter((item) => !hide.includes(item[0]) && item[1].isShowEnable) - .map((item, index) => + const statItems = Object.keys(STATS) + .filter((key) => !new_hide.includes(key)) + .concat(show_stats) + .map((key, index) => // create the text nodes, and pass index so that we can calculate the line spacing createTextNode({ - ...STATS[item[0]], + ...STATS[key], index, showIcons: show_icons, shiftValuePos: !include_all_commits, diff --git a/tests/renderStatsCard.test.js b/tests/renderStatsCard.test.js index fa28e7d3..c6151382 100644 --- a/tests/renderStatsCard.test.js +++ b/tests/renderStatsCard.test.js @@ -211,10 +211,10 @@ describe("Test renderStatsCard", () => { ).not.toHaveAttribute("x"); }); - it("should render properly with show_forks flag", () => { - document.body.innerHTML = renderStatsCard(stats, { show_forks: false }); + it("should render properly with show_stats flag", () => { + document.body.innerHTML = renderStatsCard(stats, {}); expect(queryByTestId(document.body, "forks")).toBeNull(); - document.body.innerHTML = renderStatsCard(stats, { show_forks: true }); + document.body.innerHTML = renderStatsCard(stats, { show_stats: "forks,others" }); expect(queryByTestId(document.body, "forks")).toBeDefined(); }); });