From 879937c11d08154f9afa0de7dab7b4945e452276 Mon Sep 17 00:00:00 2001 From: Fabiano Couto Date: Mon, 24 Apr 2023 10:56:14 -0300 Subject: [PATCH 01/16] feat(RankIcon): add rank_icon option (#2628) * feat(theme): add github_dark_dimmed theme * feat(theme): change github_dark_dimmed icon color * contrast ratio adjustment contrast ratio adjustment on github_dark_dimmed theme * feat(theme): readme preview * feat(theme): github themes next to each other * github themes next to each other * feat(RankIcon): add rank icon option * feat(RankIcon): extract rankIcon to icons file * feat(RankIcon): update readme * feat(RankIcon): test coverage * Update readme.md Co-authored-by: Rick Staa --------- Co-authored-by: Rick Staa --- api/index.js | 2 ++ readme.md | 13 +++++++++---- src/cards/stats-card.js | 13 +++---------- src/cards/types.d.ts | 4 ++++ src/common/icons.js | 25 ++++++++++++++++++++++++- tests/renderStatsCard.test.js | 17 +++++++++++++++++ 6 files changed, 59 insertions(+), 15 deletions(-) diff --git a/api/index.js b/api/index.js index e89c7468..29ff87f9 100644 --- a/api/index.js +++ b/api/index.js @@ -37,6 +37,7 @@ export default async (req, res) => { border_radius, number_format, border_color, + rank_icon, } = req.query; res.setHeader("Content-Type", "image/svg+xml"); @@ -92,6 +93,7 @@ export default async (req, res) => { number_format, locale: locale ? locale.toLowerCase() : null, disable_animations: parseBoolean(disable_animations), + rank_icon, }), ); } catch (err) { diff --git a/readme.md b/readme.md index 91a1cfa9..fe04a88e 100644 --- a/readme.md +++ b/readme.md @@ -216,10 +216,10 @@ You can use [GitHub's theme context](https://github.blog/changelog/2021-11-24-sp ##### Use GitHub's new media feature You can use [GitHub's new media feature](https://github.blog/changelog/2022-05-19-specify-theme-context-for-images-in-markdown-beta/) in HTML to specify whether to display images for light or dark themes. This is done using the HTML `` element in combination with the `prefers-color-scheme` media feature. - + ```html - @@ -235,7 +235,7 @@ You can use [GitHub's new media feature](https://github.blog/changelog/2022-05-1 :eyes: Show example - @@ -260,7 +260,7 @@ You can customize the appearance of your `Stats Card` or `Repo Card` however you - `border_color` - Card's border color _(hex color)_. Default: `e4e2e2` (Does not apply when `hide_border` is enabled). - `bg_color` - Card's background color _(hex color)_ **or** a gradient in the form of _angle,start,end_. Default: `fffefe` - `hide_border` - Hides the card's border _(boolean)_. Default: `false` -- `theme` - name of the theme, choose from [all available themes](./themes/README.md). Default: `default` theme. +- `theme` - name of the theme, choose from [all available themes](./themes/README.md). Default: `default` theme. - `cache_seconds` - set the cache header manually _(min: 14400, max: 86400)_. Default: `14400 seconds (4 hours)`. - `locale` - set the language in the card _(e.g. cn, de, es, etc.)_. Default: `en`. - `border_radius` - Corner rounding on the card. Default: `4.5`. @@ -280,6 +280,7 @@ You can provide multiple comma-separated values in the bg_color option to render - `hide_title` - _(boolean)_. Default: `false`. - `card_width` - Set the card's width manually _(number)_. Default: `500px (approx.)`. - `hide_rank` - _(boolean)_ hides the rank and automatically resizes the card width. Default: `false`. +- `rank_icon` - Shows alternative rank icon (i.e. `github` or `default`). Default: `default`. - `show_icons` - _(boolean)_. Default: `false`. - `include_all_commits` - Count total commits instead of just the current year commits _(boolean)_. Default: `false`. - `count_private` - Count private commits _(boolean)_. Default: `false`. @@ -459,6 +460,10 @@ Change the `?username=` value to your [Wakatime](https://wakatime.com) username. ![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=issues&show_icons=true) +- Shows Github logo instead rank level + +![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&rank_icon=github) + - Customize Border Color ![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&border_color=2e4058) diff --git a/src/cards/stats-card.js b/src/cards/stats-card.js index c60ea51d..cdb468d3 100644 --- a/src/cards/stats-card.js +++ b/src/cards/stats-card.js @@ -1,7 +1,7 @@ // @ts-check import { Card } from "../common/Card.js"; import { I18n } from "../common/I18n.js"; -import { icons } from "../common/icons.js"; +import { icons, rankIcon } from "../common/icons.js"; import { clampValue, flexLayout, @@ -108,6 +108,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { number_format = "short", locale, disable_animations = false, + rank_icon = "default", } = options; const lheight = parseInt(String(line_height), 10); @@ -294,15 +295,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { - - ${rank.level} - + ${rankIcon(rank_icon, rank?.level)} `; diff --git a/src/cards/types.d.ts b/src/cards/types.d.ts index a3abc23e..02a41b57 100644 --- a/src/cards/types.d.ts +++ b/src/cards/types.d.ts @@ -1,4 +1,5 @@ type ThemeNames = keyof typeof import("../../themes/index.js"); +type RankIcon = "default" | "github"; export type CommonOptions = { title_color: string; @@ -23,6 +24,9 @@ export type StatCardOptions = CommonOptions & { custom_title: string; disable_animations: boolean; number_format: string; + ring_color: string; + text_bold: boolean; + rank_icon: RankIcon; }; export type RepoCardOptions = CommonOptions & { diff --git a/src/common/icons.js b/src/common/icons.js index 5282a93e..948ca0bc 100644 --- a/src/common/icons.js +++ b/src/common/icons.js @@ -8,5 +8,28 @@ const icons = { fork: ``, }; -export { icons }; +/** + * Get rank icon + * + * @returns {string} - The SVG code of the rank icon + */ +const rankIcon = (rankIcon, rankLevel) => { + switch (rankIcon) { + case "github": + return ` + + `; + case "default": + default: + return ` + + ${rankLevel} + + `; + } +}; + +export { icons, rankIcon }; export default icons; diff --git a/tests/renderStatsCard.test.js b/tests/renderStatsCard.test.js index 110121ac..25c5feb6 100644 --- a/tests/renderStatsCard.test.js +++ b/tests/renderStatsCard.test.js @@ -366,4 +366,21 @@ describe("Test renderStatsCard", () => { document.body.innerHTML = renderStatsCard(stats, { number_format: "long" }); expect(getByTestId(document.body, "commits").textContent).toBe("1999"); }); + + it("should render default rank icon with level A+", () => { + document.body.innerHTML = renderStatsCard(stats, { + rank_icon: "default", + }); + expect(queryByTestId(document.body, "level-rank-icon")).toBeDefined(); + expect( + queryByTestId(document.body, "level-rank-icon").textContent.trim(), + ).toBe("A+"); + }); + + it("should render github rank icon", () => { + document.body.innerHTML = renderStatsCard(stats, { + rank_icon: "github", + }); + expect(queryByTestId(document.body, "github-rank-icon")).toBeDefined(); + }); }); From aec73d293ec6a8523b8889811d2e38f4cd3bc261 Mon Sep 17 00:00:00 2001 From: LOKESH SINGH <77314004+LokeshXs@users.noreply.github.com> Date: Mon, 24 Apr 2023 23:54:05 +0530 Subject: [PATCH 02/16] Updated the custom error there was a Typo. (#2618) "Something went while trying to retrieve the stats data using the GraphQL API." -> "Something went wrong while trying to retrieve the stats data using the GraphQL API." --- src/fetchers/stats-fetcher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fetchers/stats-fetcher.js b/src/fetchers/stats-fetcher.js index a7df1e50..fc06fce1 100644 --- a/src/fetchers/stats-fetcher.js +++ b/src/fetchers/stats-fetcher.js @@ -213,7 +213,7 @@ const fetchStats = async ( ); } throw new CustomError( - "Something went while trying to retrieve the stats data using the GraphQL API.", + "Something went wrong while trying to retrieve the stats data using the GraphQL API.", CustomError.GRAPHQL_ERROR, ); } From be0d96615d9ae3cf4b4fc6cc07921ddca7efae11 Mon Sep 17 00:00:00 2001 From: Alexandr Garbuzov <53787217+qwerty541@users.noreply.github.com> Date: Mon, 24 Apr 2023 21:24:41 +0300 Subject: [PATCH 03/16] Fix typos inside wakatime test name (#2617) --- tests/renderWakatimeCard.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/renderWakatimeCard.test.js b/tests/renderWakatimeCard.test.js index 67969bef..25e7ab4d 100644 --- a/tests/renderWakatimeCard.test.js +++ b/tests/renderWakatimeCard.test.js @@ -55,7 +55,7 @@ describe("Test Render Wakatime Card", () => { expect(document.querySelector("rect")).toHaveAttribute("rx", "4.5"); }); - it('should show "no coding activitiy this week" message when there hasn not been activity', () => { + it('should show "no coding activity this week" message when there has not been activity', () => { document.body.innerHTML = renderWakatimeCard( { ...wakaTimeData.data, From da5f82ff02c203a493abd1778715f0f498f7c37d Mon Sep 17 00:00:00 2001 From: Alexandr Garbuzov <53787217+qwerty541@users.noreply.github.com> Date: Tue, 25 Apr 2023 09:15:16 +0300 Subject: [PATCH 04/16] removed redundant comparison (#957) --- 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 cdb468d3..92701d81 100644 --- a/src/cards/stats-card.js +++ b/src/cards/stats-card.js @@ -183,7 +183,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { "nl", "zh-tw", ]; - const isLongLocale = longLocales.includes(locale) === true; + const isLongLocale = longLocales.includes(locale); // filter out hidden stats defined by user & create the text nodes const statItems = Object.keys(STATS) From 8aacec098ba92e697c9ec3b5b1b67657bfaf366e Mon Sep 17 00:00:00 2001 From: Alexandr Garbuzov <53787217+qwerty541@users.noreply.github.com> Date: Tue, 25 Apr 2023 09:16:37 +0300 Subject: [PATCH 05/16] dev (#1782) --- docs/readme_cn.md | 2 ++ docs/readme_de.md | 2 ++ docs/readme_fr.md | 2 ++ docs/readme_it.md | 2 ++ docs/readme_ja.md | 2 ++ docs/readme_kr.md | 2 ++ docs/readme_nl.md | 2 ++ docs/readme_np.md | 4 ++++ 8 files changed, 18 insertions(+) diff --git a/docs/readme_cn.md b/docs/readme_cn.md index 17fd2b71..f04324c9 100644 --- a/docs/readme_cn.md +++ b/docs/readme_cn.md @@ -53,6 +53,8 @@ Nederlands . नेपाली + . + Türkçe

喜欢这个项目?请考虑捐赠来帮助它完善! diff --git a/docs/readme_de.md b/docs/readme_de.md index 55523fe3..87f68faa 100644 --- a/docs/readme_de.md +++ b/docs/readme_de.md @@ -54,6 +54,8 @@ Nederlands . नेपाली + . + Türkçe

Du magst das Projekt? Wie wäre es mit einer kleinen Spende um es weiterhin am Leben zu erhalten? diff --git a/docs/readme_fr.md b/docs/readme_fr.md index 20996bd6..bf0ab981 100644 --- a/docs/readme_fr.md +++ b/docs/readme_fr.md @@ -53,6 +53,8 @@ Nederlands . नेपाली + . + Türkçe

Vous aimez ce projet? Pensez à faire un don pour l'améliorer! diff --git a/docs/readme_it.md b/docs/readme_it.md index 1b2df96a..05aa3e5c 100644 --- a/docs/readme_it.md +++ b/docs/readme_it.md @@ -53,6 +53,8 @@ Nederlands . नेपाली + . + Türkçe

Se ti piace questo progetto, considera la possibilità di donare per aiutare a renderlo migliore! diff --git a/docs/readme_ja.md b/docs/readme_ja.md index b00c77a7..0318984e 100644 --- a/docs/readme_ja.md +++ b/docs/readme_ja.md @@ -53,6 +53,8 @@ Nederlands . नेपाली + . + Türkçe

このプロジェクトを気に入っていただけましたか?
もしよろしければ、プロジェクトのさらなる改善のために寄付を検討して頂けると嬉しいです!

diff --git a/docs/readme_kr.md b/docs/readme_kr.md index ce0b4ad0..1d64d50d 100644 --- a/docs/readme_kr.md +++ b/docs/readme_kr.md @@ -53,6 +53,8 @@ Nederlands . नेपाली + . + Türkçe

기능들이 마음에 드시나요? 괜찮으시다면, 서비스 개선을 위해 기부를 고려해주세요! diff --git a/docs/readme_nl.md b/docs/readme_nl.md index 597f0c86..bab58176 100644 --- a/docs/readme_nl.md +++ b/docs/readme_nl.md @@ -53,6 +53,8 @@ Nederlands . नेपाली + . + Türkçe

Bevalt het project? Doneer om het te verbeteren! diff --git a/docs/readme_np.md b/docs/readme_np.md index 654427fb..510e836f 100644 --- a/docs/readme_np.md +++ b/docs/readme_np.md @@ -49,8 +49,12 @@ Italiano · 한국어 + . + Nederlands · नेपाली + . + Türkçe

परियोजना मनपर्‍यो? तपाईं मद्दत गर्न सक्नुहुन्छ यो परियोजना बढ्न From 21a9ba4faeae5072f5c46009ab2f11bc3258508b Mon Sep 17 00:00:00 2001 From: Alexandr Garbuzov <53787217+qwerty541@users.noreply.github.com> Date: Tue, 25 Apr 2023 09:17:10 +0300 Subject: [PATCH 06/16] fix path to powered by vercel image (#1792) --- docs/readme_tr.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/readme_tr.md b/docs/readme_tr.md index 7b11cf37..4e67c7ed 100644 --- a/docs/readme_tr.md +++ b/docs/readme_tr.md @@ -409,7 +409,7 @@ Teşekkürler! :heart: --- -[![https://vercel.com?utm_source=github_readme_stats_team&utm_campaign=oss](./powered-by-vercel.svg)](https://vercel.com?utm_source=github_readme_stats_team&utm_campaign=oss) +[![https://vercel.com?utm_source=github_readme_stats_team&utm_campaign=oss](../powered-by-vercel.svg)](https://vercel.com?utm_source=github_readme_stats_team&utm_campaign=oss) Katkılara açığız! <3 From da46a5093cd0f6c4a537196cb9e67865bbbe3aed Mon Sep 17 00:00:00 2001 From: Alexandr Garbuzov <53787217+qwerty541@users.noreply.github.com> Date: Tue, 25 Apr 2023 09:17:50 +0300 Subject: [PATCH 07/16] Synchonize cache seconds min value inside docs translations with main readme (#2616) --- docs/readme_cn.md | 2 +- docs/readme_de.md | 2 +- docs/readme_es.md | 2 +- docs/readme_fr.md | 2 +- docs/readme_it.md | 2 +- docs/readme_ja.md | 2 +- docs/readme_kr.md | 2 +- docs/readme_nl.md | 2 +- docs/readme_np.md | 2 +- docs/readme_pt-BR.md | 2 +- docs/readme_tr.md | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/readme_cn.md b/docs/readme_cn.md index f04324c9..d6487b66 100644 --- a/docs/readme_cn.md +++ b/docs/readme_cn.md @@ -140,7 +140,7 @@ dark, radical, merko, gruvbox, tokyonight, onedark, cobalt, synthwave, highcontr - `bg_color` - 卡片背景颜色 _(十六进制色码)_ **或者** 以 _angle,start,end_ 的形式渐变 - `hide_border` - 隐藏卡的边框 _(布尔值)_ - `theme` - 主题名称,从[所有可用主题](../themes/README.md)中选择 -- `cache_seconds` - 手动设置缓存头 _(最小值: 1800,最大值: 86400)_ +- `cache_seconds` - 手动设置缓存头 _(最小值: 14400,最大值: 86400)_ - `locale` - 在卡片中设置语言 _(例如 cn, de, es, 等等)_ ##### bg_color 渐变 diff --git a/docs/readme_de.md b/docs/readme_de.md index 87f68faa..8756670e 100644 --- a/docs/readme_de.md +++ b/docs/readme_de.md @@ -130,7 +130,7 @@ Du kannst das Erscheinungsbild deiner `Stats Card` oder `Repo Card`, mithilfe vo - `bg_color` - Hintergrundfarbe _(hex color)_ **oder** ein Farbverlauf in der Form von _winkel,start,ende_ - `hide_border` - Blendet den Rand der Karte aus _(Boolean)_ - `theme` - Name des Erscheinungsbildes/Themes [alle verfügbaren Themes](../themes/README.md) -- `cache_seconds` - manuelles festlegen der Cachezeiten _(min: 1800, max: 86400)_ +- `cache_seconds` - manuelles festlegen der Cachezeiten _(min: 14400, max: 86400)_ - `locale` - Stellen Sie die Sprache auf der Karte ein _(z.B. cn, de, es, etc.)_ ##### Farbverlauf in bg_color diff --git a/docs/readme_es.md b/docs/readme_es.md index 5ddceec7..b477e5c7 100644 --- a/docs/readme_es.md +++ b/docs/readme_es.md @@ -142,7 +142,7 @@ Puedes personalizar el aspecto de tu `Tarjeta de Estadísticas` o `Tarjeta de Re - `bg_color` - Color de fondo _(hex color)_ - `hide_border` - Oculta el borde de la tarjeta _(booleano)_ - `theme` - Nombre del tema, elige uno de [todos los temas disponible ](../themes/README.md) -- `cache_seconds` - Cache _(min: 1800, max: 86400)_ +- `cache_seconds` - Cache _(min: 14400, max: 86400)_ - `locale` - configurar el idioma en la tarjeta _(p.ej. cn, de, es, etc.)_ ##### Gradiente en `bg_color` diff --git a/docs/readme_fr.md b/docs/readme_fr.md index bf0ab981..ce0d3d49 100644 --- a/docs/readme_fr.md +++ b/docs/readme_fr.md @@ -140,7 +140,7 @@ Vous pouvez personnaliser l'apparence de votre `Carte des stats` ou `Carte de d - `bg_color` - Couleur du fond de la carte _(hex color)_ **ou** un gradiant de la forme _angle,start,end_ - `hide_border` - Cache la bordure de la carte _(booléen)_ - `theme` - Nom du thème, parmis [tous les thèmes disponibles](../themes/README.md) -- `cache_seconds` - Paramétrer le cache manuellement _(min: 1800, max: 86400)_ +- `cache_seconds` - Paramétrer le cache manuellement _(min: 14400, max: 86400)_ - `locale` - définir la langue de la carte _(par exemple. cn, de, es, etc.)_ ##### Gradient in bg_color diff --git a/docs/readme_it.md b/docs/readme_it.md index 05aa3e5c..e54af7dc 100644 --- a/docs/readme_it.md +++ b/docs/readme_it.md @@ -140,7 +140,7 @@ Puoi personalizzare l'aspetto delle tue `Stats Card` o delle `Repo Card` in qual - `bg_color` - Colore dello sfondo _(in esadecimale)_ **oppure** un gradiente nella forma _angolo,inizio,fine_ - `hide_border` - Nasconde il bordo della carta _(booleano)_ - `theme` - Nome del tema, dai un'occhiata a [tutti i temi disponibili](../themes/README.md) -- `cache_seconds` - Specifica manualmente il valore di cache, in secondi _(min: 1800, max: 86400)_ +- `cache_seconds` - Specifica manualmente il valore di cache, in secondi _(min: 14400, max: 86400)_ - `locale` - Impostare la lingua nella scheda _(per esempio. cn, de, es, eccetera.)_ ##### Gradiente nello sfondo diff --git a/docs/readme_ja.md b/docs/readme_ja.md index 0318984e..2c2def7f 100644 --- a/docs/readme_ja.md +++ b/docs/readme_ja.md @@ -141,7 +141,7 @@ dark, radical, merko, gruvbox, tokyonight, onedark, cobalt, synthwave, highcontr - `bg_color` - 背景の色 _(16 進数カラーコード)_ **または** _angle,start,end_ の形式でグラデーションを指定することも可 - `hide_border` - カードの境界線を非表示にします _(ブール値)_ - `theme` - [使用可能なテーマ一覧](../themes/README.md) から選んだテーマ名 -- `cache_seconds` - キャッシュ時間の秒数 _(最小値: 1800, 最大値: 86400)_ +- `cache_seconds` - キャッシュ時間の秒数 _(最小値: 14400, 最大値: 86400)_ - `locale` - カードに言語を設定する _(例えば cn, de, es, 等)_ ##### bg_color の グラデーション指定 diff --git a/docs/readme_kr.md b/docs/readme_kr.md index 1d64d50d..4a1c57cc 100644 --- a/docs/readme_kr.md +++ b/docs/readme_kr.md @@ -151,7 +151,7 @@ dark, radical, merko, gruvbox, tokyonight, onedark, cobalt, synthwave, highcontr - `bg_color` - 카드의 배경 색상 _(hex color)_ **혹은** 다음 양식으로 그라데이션 주기 _angle,start,end_ - `hide_border` - 카드의 테두리 표시 여부 _(boolean)_ - `theme` - 테마의 이름, [사용 가능한 모든 테마](../themes/README.md) 에서 선택 -- `cache_seconds` - 수동으로 캐시 헤더 설정 _(min: 1800, max: 86400)_ +- `cache_seconds` - 수동으로 캐시 헤더 설정 _(min: 14400, max: 86400)_ - `locale` - 카드에 표시할 언어 _(e.g. kr, cn, de, es, etc.)_ ##### 배경에 그라데이션 주기 diff --git a/docs/readme_nl.md b/docs/readme_nl.md index bab58176..b279c4f7 100644 --- a/docs/readme_nl.md +++ b/docs/readme_nl.md @@ -144,7 +144,7 @@ Je kan het uiterlijk van je `Statistieken kaart` of `Repo kaart` aanpassen hoe j - `bg_color` - Achtergrond kleur van de kaart _(hex kleur)_ **of** een verloop van kleuren in het formaat van _graden,start,einde_ - `hide_border` - Verbergt de rand van de kaart _(boolean)_ - `theme` - Naam van het thema, kies uit [alle beschikbare thema\'s](../themes/README.md) -- `cache_seconds` - Stel de cache header handmatig in _(min: 1800, max: 86400)_ +- `cache_seconds` - Stel de cache header handmatig in _(min: 14400, max: 86400)_ - `locale` - Stel taal van de kaart in _(e.g. cn, de, es, etc.)_ ##### Kleurenverloop in bg_color (achtergrond kleur): diff --git a/docs/readme_np.md b/docs/readme_np.md index 510e836f..e90ee57b 100644 --- a/docs/readme_np.md +++ b/docs/readme_np.md @@ -142,7 +142,7 @@ dark, radical, merko, gruvbox, tokyonight, onedark, cobalt, synthwave, highcontr - `bg_color` - Card's background color _(hex color)_ **or** a gradient in the form of _angle,start,end_ - `hide_border` - Hides the card's border _(boolean)_ - `theme` - name of the theme, choose from [all available themes](./themes/README.md) -- `cache_seconds` - set the cache header manually _(min: 1800, max: 86400)_ +- `cache_seconds` - set the cache header manually _(min: 14400, max: 86400)_ - `locale` - set the language in the card _(e.g. cn, de, es, etc.)_ ##### Gradient in bg_color diff --git a/docs/readme_pt-BR.md b/docs/readme_pt-BR.md index 62c23dc5..1ac57716 100644 --- a/docs/readme_pt-BR.md +++ b/docs/readme_pt-BR.md @@ -141,7 +141,7 @@ Personalize a aparência do seu `Stats Card` ou `Repo Card` da maneira que desej - `bg_color` - Cor de fundo do cartão _(hex color)_ - `hide_border` - Esconde a borda do cartão _(boleano)_ - `theme` - Nome do tema, escolha em [todos os temas disponíveis](../themes/README.md) -- `cache_seconds` - Defina o cabeçalho do cache manualmente _(min: 1800, max: 86400)_ +- `cache_seconds` - Defina o cabeçalho do cache manualmente _(min: 14400, max: 86400)_ - `locale` - defina o idioma no cartão _(por exemplo. cn, de, es, etc.)_ > Nota sobre o cache: Cartões de repositório tem um cache padrão de 30 minutos (1800 segundos), se o número a contagem de forks e contagem de estrelas é menor que 1 mil o padrão é 2 horas (7200 segundos). Note também que o cache é limitado a um mínimo de 30 minutos e um máximo de 24 horas. diff --git a/docs/readme_tr.md b/docs/readme_tr.md index 4e67c7ed..d8ae9778 100644 --- a/docs/readme_tr.md +++ b/docs/readme_tr.md @@ -143,7 +143,7 @@ dark, radical, merko, gruvbox, tokyonight, onedark, cobalt, synthwave, highcontr - `bg_color` - Kartın arkaplan rengi _(hex color / hex rengi)_ **ya da** gradient şeklinde _açı,başlangıç,bitiş_ - `hide_border` - Kartın çerçevelerini gizler _(boolean)_ - `theme` - Temanın rengi [tüm temalar](./themes/README.md) -- `cache_seconds` - Manuel olarak cache'i belirleyebilirsiniz _(en az: 1800, en fazla: 86400)_ +- `cache_seconds` - Manuel olarak cache'i belirleyebilirsiniz _(en az: 14400, en fazla: 86400)_ - `locale` - Karttaki dili seçebilirsiniz _(örneğin; tr, cn, de, es, vb.)_ ##### bg_color'da Gradient From 5577bbf07fae7f0e2fcbed24042a59e5442434dc Mon Sep 17 00:00:00 2001 From: kitswas <90329875+kitswas@users.noreply.github.com> Date: Tue, 25 Apr 2023 11:49:05 +0530 Subject: [PATCH 08/16] New top language algorithm implementation (#1732) * Reduced vercel maxDuration * Implemented new algorithm for Top Langs * Revert "Reduced vercel maxDuration" This reverts commit b0bc626efe12c738cf5005e7f11c7d2a07b6387a. * Added documentation * Fixed broken implementation * Update fetchTopLanguages.test.js Changed tests * Now uses the general formula The parameters p and q can be set by the user. * Updated tests and added new test * Added new test New test for order by repo count. * Updated documentation Added explanation and examples for new options. * Updated documentation This was overwritten in the merge commit. * docs: improve docs and fix tests * Renamed parameters Renamed `p` and `q` to `size_weight` and `count_weight`, respectively. * Updated the documentation Changes introduced in f2516d60a442dfdbb9e24ddda8743664bcb8064d --------- Co-authored-by: rickstaa --- api/top-langs.js | 4 +++ readme.md | 40 +++++++++++++++------ src/fetchers/top-languages-fetcher.js | 24 +++++++++++-- tests/fetchTopLanguages.test.js | 52 ++++++++++++++++++++++++--- 4 files changed, 104 insertions(+), 16 deletions(-) diff --git a/api/top-langs.js b/api/top-langs.js index e67d9533..cde0a9af 100644 --- a/api/top-langs.js +++ b/api/top-langs.js @@ -25,6 +25,8 @@ export default async (req, res) => { layout, langs_count, exclude_repo, + size_weight, + count_weight, custom_title, locale, border_radius, @@ -46,6 +48,8 @@ export default async (req, res) => { const topLangs = await fetchTopLanguages( username, parseArray(exclude_repo), + size_weight, + count_weight, ); const cacheSeconds = clampValue( diff --git a/readme.md b/readme.md index fe04a88e..76b46e0e 100644 --- a/readme.md +++ b/readme.md @@ -310,6 +310,8 @@ You can provide multiple comma-separated values in the bg_color option to render - `custom_title` - Sets a custom title for the card _(string)_. Default `Most Used Languages`. - `disable_animations` - Disables all animations in the card _(boolean)_. Default: `false`. - `hide_progress` - It uses the compact layout option, hides percentages, and removes the bars. Default: `false`. +- `size_weight` - Configures language stats algorithm _(number)_ (see [Language stats algorithm](#Language-stats-algorithm)), defaults to 1. +- `count_weight` - Configures language stats algorithm _(number)_ (see [Language stats algorithm](#Language-stats-algorithm)), defaults to 0. > **Warning** > Language names should be URI-escaped, as specified in [Percent Encoding](https://en.wikipedia.org/wiki/Percent-encoding) @@ -359,7 +361,25 @@ Use [show_owner](#customization) variable to include the repo's owner username The top languages card shows a GitHub user's most frequently used top language. > **Note** -> Top Languages does not indicate my skill level or anything like that; it's a GitHub metric to determine which languages have the most code on GitHub. It is a new feature of github-readme-stats. +> Top Languages does not indicate the user's skill level or anything like that; it's a GitHub metric to determine which languages have the most code on GitHub. It is a new feature of github-readme-stats. + +### Language stats algorithm + +We use the following algorithm to calculate the languages percentages on the language card: + +```js +ranking_index = (byte_count ^ size_weight) * (repo_count ^ count_weight) +``` + +By default, only the byte count is used for determining the languages percentages shown on the language card (i.e. `size_weight=1` and `count_weight=0`). You can, however, use the `&size_weight=` and `&count_weight=` options to weight the language usage calculation. The values must be positive real numbers. [More details about the algorithm can be found here](https://github.com/anuraghazra/github-readme-stats/issues/1600#issuecomment-1046056305). + +- `&size_weight=1&count_weight=0` - _(default)_ Orders by byte count. +- `&size_weight=0.5&count_weight=0.5` - _(recommended)_ Uses both byte and repo count for ranking +- `&size_weight=0&count_weight=1` - Orders by repo count + +```md +[![Top Langs](https://github-readme-stats.vercel.app/api/top-langs/?username=anuraghazra&size_weight=0.5&count_weight=0.5)](https://github.com/anuraghazra/github-readme-stats) +``` ### Usage @@ -419,7 +439,7 @@ You can use the `&hide_progress=true` option to hide the percentages and the pro [![Top Langs](https://github-readme-stats.vercel.app/api/top-langs/?username=anuraghazra&layout=compact)](https://github.com/anuraghazra/github-readme-stats) -- Hidden progress bars +- Hidden progress bars [![Top Langs](https://github-readme-stats.vercel.app/api/top-langs/?username=anuraghazra&hide_progress=true)](https://github.com/anuraghazra/github-readme-stats) @@ -564,14 +584,14 @@ Since the GitHub API only allows 5k requests per hour, my `https://github-readme

:hammer_and_wrench: Step-by-step guide for deploying on other platforms -1. Fork or clone this repo as per your needs -2. Add `express` to the dependencies section of `package.json` -https://github.com/anuraghazra/github-readme-stats/blob/ba7c2f8b55eac8452e479c8bd38b044d204d0424/package.json#L54-L61 -3. Run `npm i` if needed (initial setup) -4. Run `node express.js` to start the server, or set the entry point to `express.js` in `package.json` if you're deploying on a managed service -https://github.com/anuraghazra/github-readme-stats/blob/ba7c2f8b55eac8452e479c8bd38b044d204d0424/package.json#L11 -5. You're done 🎉 -
+1. Fork or clone this repo as per your needs +2. Add `express` to the dependencies section of `package.json` + +3. Run `npm i` if needed (initial setup) +4. Run `node express.js` to start the server, or set the entry point to `express.js` in `package.json` if you're deploying on a managed service + +5. You're done 🎉 + ### Keep your fork up to date diff --git a/src/fetchers/top-languages-fetcher.js b/src/fetchers/top-languages-fetcher.js index 86d79443..45b2ba7d 100644 --- a/src/fetchers/top-languages-fetcher.js +++ b/src/fetchers/top-languages-fetcher.js @@ -54,7 +54,12 @@ const fetcher = (variables, token) => { * @param {string[]} exclude_repo List of repositories to exclude. * @returns {Promise} Top languages data. */ -const fetchTopLanguages = async (username, exclude_repo = []) => { +const fetchTopLanguages = async ( + username, + exclude_repo = [], + size_weight = 1, + count_weight = 0, +) => { if (!username) throw new MissingParamError(["username"]); const res = await retryer(fetcher, { login: username }); @@ -101,6 +106,8 @@ const fetchTopLanguages = async (username, exclude_repo = []) => { .sort((a, b) => b.size - a.size) .filter((name) => !repoToHide[name.name]); + let repoCount = 0; + repoNodes = repoNodes .filter((node) => node.languages.edges.length > 0) // flatten the list of language nodes @@ -111,9 +118,14 @@ const fetchTopLanguages = async (username, exclude_repo = []) => { // if we already have the language in the accumulator // & the current language name is same as previous name - // add the size to the language size. + // add the size to the language size and increase repoCount. if (acc[prev.node.name] && prev.node.name === acc[prev.node.name].name) { langSize = prev.size + acc[prev.node.name].size; + repoCount += 1; + } else { + // reset repoCount to 1 + // language must exist in at least one repo to be detected + repoCount = 1; } return { ...acc, @@ -121,10 +133,18 @@ const fetchTopLanguages = async (username, exclude_repo = []) => { name: prev.node.name, color: prev.node.color, size: langSize, + count: repoCount, }, }; }, {}); + Object.keys(repoNodes).forEach((name) => { + // comparison index calculation + repoNodes[name].size = + Math.pow(repoNodes[name].size, size_weight) * + Math.pow(repoNodes[name].count, count_weight); + }); + const topLangs = Object.keys(repoNodes) .sort((a, b) => repoNodes[b].size - repoNodes[a].size) .reduce((result, key) => { diff --git a/tests/fetchTopLanguages.test.js b/tests/fetchTopLanguages.test.js index 24416cd2..c3f558bf 100644 --- a/tests/fetchTopLanguages.test.js +++ b/tests/fetchTopLanguages.test.js @@ -60,20 +60,22 @@ const error = { }; describe("FetchTopLanguages", () => { - it("should fetch correct language data", async () => { + it("should fetch correct language data while using the new calculation", async () => { mock.onPost("https://api.github.com/graphql").reply(200, data_langs); - let repo = await fetchTopLanguages("anuraghazra"); + let repo = await fetchTopLanguages("anuraghazra", [], 0.5, 0.5); expect(repo).toStrictEqual({ HTML: { color: "#0f0", + count: 2, name: "HTML", - size: 200, + size: 20.000000000000004, }, javascript: { color: "#0ff", + count: 2, name: "javascript", - size: 200, + size: 20.000000000000004, }, }); }); @@ -85,17 +87,59 @@ describe("FetchTopLanguages", () => { expect(repo).toStrictEqual({ HTML: { color: "#0f0", + count: 1, name: "HTML", size: 100, }, javascript: { color: "#0ff", + count: 2, name: "javascript", size: 200, }, }); }); + it("should fetch correct language data while using the old calculation", async () => { + mock.onPost("https://api.github.com/graphql").reply(200, data_langs); + + let repo = await fetchTopLanguages("anuraghazra", [], 1, 0); + expect(repo).toStrictEqual({ + HTML: { + color: "#0f0", + count: 2, + name: "HTML", + size: 200, + }, + javascript: { + color: "#0ff", + count: 2, + name: "javascript", + size: 200, + }, + }); + }); + + it("should rank languages by the number of repositories they appear in", async () => { + mock.onPost("https://api.github.com/graphql").reply(200, data_langs); + + let repo = await fetchTopLanguages("anuraghazra", [], 0, 1); + expect(repo).toStrictEqual({ + HTML: { + color: "#0f0", + count: 2, + name: "HTML", + size: 2, + }, + javascript: { + color: "#0ff", + count: 2, + name: "javascript", + size: 2, + }, + }); + }); + it("should throw error", async () => { mock.onPost("https://api.github.com/graphql").reply(200, error); From f5f0a79bc12a35c58609f3fa6ced2f6722bbfdf1 Mon Sep 17 00:00:00 2001 From: Rick Staa Date: Fri, 28 Apr 2023 04:00:13 +0200 Subject: [PATCH 09/16] feat: improve CONTRIBUTING.md (#2609) --- CONTRIBUTING.md | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0d4b558a..7d450d60 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,11 +2,11 @@ We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's: -- Reporting an issue -- Discussing the current state of the code -- Submitting a fix -- Proposing new features -- Becoming a maintainer +- Reporting [an issue](https://github.com/anuraghazra/github-readme-stats/issues/new?assignees=&labels=bug&template=bug_report.yml). +- [Discussing](https://github.com/anuraghazra/github-readme-stats/discussions) the current state of the code. +- Submitting [a fix](https://github.com/anuraghazra/github-readme-stats/compare). +- Proposing [new features](https://github.com/anuraghazra/github-readme-stats/issues/new?assignees=&labels=enhancement&template=feature_request.yml). +- Becoming a maintainer. ## All Changes Happen Through Pull Requests @@ -33,11 +33,15 @@ _(make sure you already have a [Vercel](https://vercel.com/) account)_ 1. Install [Vercel CLI](https://vercel.com/download). 2. Fork the repository and clone the code to your local machine. 3. Run `npm install` in the repository root. -4. Run the command "vercel" in the root and follow the steps there. +4. Run the command `vercel` in the root and follow the steps there. 5. Open `vercel.json` and set the maxDuration to 10. 6. Create a `.env` file in the root of the directory. -7. In the .env file add a new variable named "PAT_1" with your [GitHub Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). -8. Run the command "vercel dev" to start a development server at . +7. In the .env file add a new variable named `PAT_1` with your [GitHub Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). +8. Run the command `vercel dev` to start a development server at . +9. The cards will then be available from this local endpoint (i.e. `https://localhost:3000/api?username=anuraghazra`). + +> **Note** +> You can also debug any tests using the [VSCode Jest extension](https://marketplace.visualstudio.com/items?itemName=Orta.vscode-jest). For more information see https://github.com/jest-community/vscode-jest/issues/912. ## Themes Contribution From fd64333211fa9f39f59028fcb3892d2cf2fbb57a Mon Sep 17 00:00:00 2001 From: Rick Staa Date: Fri, 28 Apr 2023 04:00:33 +0200 Subject: [PATCH 10/16] docs: update give logo (#2605) --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 76b46e0e..6b4cefdf 100644 --- a/readme.md +++ b/readme.md @@ -66,7 +66,7 @@

Love the project? Please consider donating to help it improve!

- Give india logo + Give india logo Are you considering supporting the project by donating? Please DO NOT!! From 30a45d3c136033a0459d0c0423a4836d78e8b0e7 Mon Sep 17 00:00:00 2001 From: Alexandr Garbuzov <53787217+qwerty541@users.noreply.github.com> Date: Fri, 28 Apr 2023 10:50:57 +0300 Subject: [PATCH 11/16] Fixed typo in word color inside README (#2652) --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 6b4cefdf..538b4e88 100644 --- a/readme.md +++ b/readme.md @@ -183,7 +183,7 @@ We have included a `transparent` theme that has a transparent background. This t ##### Add transparent alpha channel to a themes bg_color -You can use the `bg_color` parameter to make any of [the available themes](./themes/README.md) transparent. This is done by setting the `bg_color` to a colour with a transparent alpha channel (i.e. `bg_color=00000000`): +You can use the `bg_color` parameter to make any of [the available themes](./themes/README.md) transparent. This is done by setting the `bg_color` to a color with a transparent alpha channel (i.e. `bg_color=00000000`): ```md ![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&bg_color=00000000) From 6eebfe36e8406730ae13d088060eb5ea6503e1d5 Mon Sep 17 00:00:00 2001 From: Alexandr Garbuzov <53787217+qwerty541@users.noreply.github.com> Date: Fri, 28 Apr 2023 10:51:24 +0300 Subject: [PATCH 12/16] Fixed docs typo inside src/common/utils.js (#2651) --- src/common/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/utils.js b/src/common/utils.js index c600c717..f8254460 100644 --- a/src/common/utils.js +++ b/src/common/utils.js @@ -392,7 +392,7 @@ const lowercaseTrim = (name) => name.toLowerCase().trim(); /** * Split array of languages in two columns. * - * @template T Langauge object. + * @template T Language object. * @param {Array} arr Array of languages. * @param {number} perChunk Number of languages per column. * @returns {Array} Array of languages split in two columns. From a82a617a37a986c9ee7f9285190c82d106034974 Mon Sep 17 00:00:00 2001 From: Alexandr Garbuzov <53787217+qwerty541@users.noreply.github.com> Date: Fri, 28 Apr 2023 10:51:54 +0300 Subject: [PATCH 13/16] Fixed several typos inside preview theme script (#2650) --- scripts/preview-theme.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/preview-theme.js b/scripts/preview-theme.js index e18c01b8..57b792a3 100644 --- a/scripts/preview-theme.js +++ b/scripts/preview-theme.js @@ -26,9 +26,9 @@ const FAIL_TEXT = ` \rUnfortunately, your theme PR contains an error or does not adhere to our [theme guidelines](https://github.com/anuraghazra/github-readme-stats/blob/master/CONTRIBUTING.md#themes-contribution). Please fix the issues below, and we will review your\ \r PR again. This pull request will **automatically close in 20 days** if no changes are made. After this time, you must re-open the PR for it to be reviewed. `; -const THEME_CONTRIB_GUIDELINESS = ` +const THEME_CONTRIB_GUIDELINES = ` \rHi, thanks for the theme contribution. Please read our theme [contribution guidelines](https://github.com/anuraghazra/github-readme-stats/blob/master/CONTRIBUTING.md#themes-contribution). - \rWe are currently only accepting color combinations from any VSCode theme or themes with good colour combinations to minimize bloating the themes collection. + \rWe are currently only accepting color combinations from any VSCode theme or themes with good color combinations to minimize bloating the themes collection. \r> Also, note that if this theme is exclusively for your personal use, then instead of adding it to our theme collection, you can use card [customization options](https://github.com/anuraghazra/github-readme-stats#customization). `; @@ -363,7 +363,7 @@ export const run = async () => { debug(`Context: ${inspect(github.context)}`); let commentBody = ` \r# ${COMMENT_TITLE} - \r${THEME_CONTRIB_GUIDELINESS} + \r${THEME_CONTRIB_GUIDELINES} `; const ccc = new ColorContrastChecker(); OCTOKIT = github.getOctokit(getGithubToken()); From 31d1ab43d0cae0ecbaba5748fb6a5ca9ae1c7609 Mon Sep 17 00:00:00 2001 From: Alexandr Garbuzov <53787217+qwerty541@users.noreply.github.com> Date: Fri, 28 Apr 2023 18:48:34 +0300 Subject: [PATCH 14/16] Fixed todo inside stats card data fetcher (#2649) --- src/calculateRank.js | 15 ++++++++------- src/fetchers/stats-fetcher.js | 1 - 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/calculateRank.js b/src/calculateRank.js index 24845bc7..215c24d8 100644 --- a/src/calculateRank.js +++ b/src/calculateRank.js @@ -29,13 +29,14 @@ const normalcdf = (mean, sigma, to) => { /** * Calculates the users rank. * - * @param {number} totalRepos Total number of repos. - * @param {number} totalCommits Total number of commits. - * @param {number} contributions The number of contributions. - * @param {number} followers The number of followers. - * @param {number} prs The number of pull requests. - * @param {number} issues The number of issues. - * @param {number} stargazers The number of stars. + * @param {object} params Parameters on which the user's rank depends. + * @param {number} params.totalRepos Total number of repos. + * @param {number} params.totalCommits Total number of commits. + * @param {number} params.contributions The number of contributions. + * @param {number} params.followers The number of followers. + * @param {number} params.prs The number of pull requests. + * @param {number} params.issues The number of issues. + * @param {number} params.stargazers The number of stars. * @returns {{level: string, score: number}}} The users rank. */ const calculateRank = ({ diff --git a/src/fetchers/stats-fetcher.js b/src/fetchers/stats-fetcher.js index fc06fce1..8603e38b 100644 --- a/src/fetchers/stats-fetcher.js +++ b/src/fetchers/stats-fetcher.js @@ -259,7 +259,6 @@ const fetchStats = async ( return prev + curr.stargazers.totalCount; }, 0); - // @ts-ignore // TODO: Fix this. stats.rank = calculateRank({ totalCommits: stats.totalCommits, totalRepos: user.repositories.totalCount, From 3bd6519d39cbd6b0a078af17c2756b2804d85fb3 Mon Sep 17 00:00:00 2001 From: Rick Staa Date: Sat, 29 Apr 2023 04:55:37 +0200 Subject: [PATCH 15/16] docs: fix README language card usage order (#2659) --- readme.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/readme.md b/readme.md index 538b4e88..ae18c9e6 100644 --- a/readme.md +++ b/readme.md @@ -363,6 +363,16 @@ The top languages card shows a GitHub user's most frequently used top language. > **Note** > Top Languages does not indicate the user's skill level or anything like that; it's a GitHub metric to determine which languages have the most code on GitHub. It is a new feature of github-readme-stats. +### Usage + +Copy-paste this code into your readme and change the links. + +Endpoint: `api/top-langs?username=anuraghazra` + +```md +[![Top Langs](https://github-readme-stats.vercel.app/api/top-langs/?username=anuraghazra)](https://github.com/anuraghazra/github-readme-stats) +``` + ### Language stats algorithm We use the following algorithm to calculate the languages percentages on the language card: @@ -381,16 +391,6 @@ By default, only the byte count is used for determining the languages percentage [![Top Langs](https://github-readme-stats.vercel.app/api/top-langs/?username=anuraghazra&size_weight=0.5&count_weight=0.5)](https://github.com/anuraghazra/github-readme-stats) ``` -### Usage - -Copy-paste this code into your readme and change the links. - -Endpoint: `api/top-langs?username=anuraghazra` - -```md -[![Top Langs](https://github-readme-stats.vercel.app/api/top-langs/?username=anuraghazra)](https://github.com/anuraghazra/github-readme-stats) -``` - ### Exclude individual repositories You can use the `&exclude_repo=repo1,repo2` parameter to exclude individual repositories. From 2f4279e73883cb64712a5083a1577c602202b6a4 Mon Sep 17 00:00:00 2001 From: Alexandr Garbuzov <53787217+qwerty541@users.noreply.github.com> Date: Sun, 30 Apr 2023 09:20:26 +0300 Subject: [PATCH 16/16] Fixed vscode type error in get card colors function (#2660) --- src/common/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/utils.js b/src/common/utils.js index f8254460..47e10614 100644 --- a/src/common/utils.js +++ b/src/common/utils.js @@ -194,15 +194,15 @@ const flexLayout = ({ items, gap, direction, sizes = [] }) => { /** * Returns theme based colors with proper overrides and defaults. * - * @param {Object[]} args Function arguments. + * @param {Object} args Function arguments. * @param {string} args.title_color Card title color. * @param {string} args.text_color Card text color. * @param {string} args.icon_color Card icon color. * @param {string} args.bg_color Card background color. * @param {string} args.border_color Card border color. + * @param {string} args.ring_color Card ring color. * @param {string} args.theme Card theme. * @param {string} args.fallbackTheme Fallback theme. - * */ const getCardColors = ({ title_color,