Skip to content

Commit

Permalink
Stats card: migrate from show_total_reviews to show option (resolves #…
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty541 committed Jun 17, 2023
1 parent 1997328 commit c0d9987
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default async (req, res) => {
number_format,
border_color,
rank_icon,
show_total_reviews,
show,
} = req.query;
res.setHeader("Content-Type", "image/svg+xml");

Expand Down Expand Up @@ -96,7 +96,7 @@ export default async (req, res) => {
locale: locale ? locale.toLowerCase() : null,
disable_animations: parseBoolean(disable_animations),
rank_icon,
show_total_reviews: parseBoolean(show_total_reviews),
show: parseArray(show),
}),
);
} catch (err) {
Expand Down
13 changes: 12 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Please visit [this link](https://give.do/fundraisers/stand-beside-the-victims-of

- [GitHub Stats Card](#github-stats-card)
- [Hiding individual stats](#hiding-individual-stats)
- [Showing additional individual stats](#showing-additional-individual-stats)
- [Showing icons](#showing-icons)
- [Themes](#themes)
- [Customization](#customization)
Expand Down Expand Up @@ -149,6 +150,16 @@ You can pass a query parameter `&hide=` to hide any specific stats with comma-se
![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=contribs,prs)
```

### Showing additional individual stats

You can pass a query parameter `&show=` to show any specific stats with comma-separated values.

> Options: `&show=reviews`
```md
![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&show=reviews)
```

### Showing icons

To enable icons, you can pass `&show_icons=true` in the query param, like so:
Expand Down Expand Up @@ -306,7 +317,7 @@ You can provide multiple comma-separated values in the bg_color option to render
- `disable_animations` - Disables all animations in the card _(boolean)_. Default: `false`.
- `ring_color` - Color of the rank circle _(hex color)_. Defaults to the theme ring color if it exists and otherwise the title color.
- `number_format` - Switch between two available formats for displaying the card values `short` (i.e. `6.6k`) and `long` (i.e. `6626`). Default: `short`.
- `show_total_reviews` - Show total PR reviews _(boolean)_. Default: `false`.
- `show` - Show total PR reviews _(boolean)_. Default: `false`.

> **Note**
> When hide_rank=`true`, the minimum card width is 270 px + the title length and padding.
Expand Down
4 changes: 2 additions & 2 deletions src/cards/stats-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
locale,
disable_animations = false,
rank_icon = "default",
show_total_reviews = false,
show = [],
} = options;

const lheight = parseInt(String(line_height), 10);
Expand Down Expand Up @@ -161,7 +161,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
id: "prs",
};

if (show_total_reviews) {
if (show.includes("reviews")) {
STATS.reviews = {
icon: icons.reviews,
label: i18n.t("statcard.reviews"),
Expand Down
2 changes: 1 addition & 1 deletion src/cards/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type StatCardOptions = CommonOptions & {
ring_color: string;
text_bold: boolean;
rank_icon: RankIcon;
show_total_reviews: boolean;
show: string[];
};

export type RepoCardOptions = CommonOptions & {
Expand Down
2 changes: 1 addition & 1 deletion tests/renderStatsCard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("Test renderStatsCard", () => {

it("should show total reviews", () => {
document.body.innerHTML = renderStatsCard(stats, {
show_total_reviews: true,
show: ["reviews"],
});

expect(
Expand Down

0 comments on commit c0d9987

Please sign in to comment.