Skip to content

Commit b6fb004

Browse files
authored
feat: add new option revert (#478)
1 parent a9a9304 commit b6fb004

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

api/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { isValidHexColor, isValidGradient } from "../src/common/utils";
2727
* @property {string|undefined} showItems - Items to show.
2828
* @property {boolean|string} hideStroke - Toggle for hiding strokes.
2929
* @property {boolean|string} hideBorder - Toggle for hiding borders.
30+
* @property {boolean|string} Revert - Invert display order, stats to left and image to right.
3031
* @property {number|string} photoQuality - Photo image quality.
3132
* @property {number|string} photoResize - Photo image resize.
3233
*/
@@ -48,6 +49,7 @@ type UiConfig = {
4849
showItems: string | undefined;
4950
hideStroke: boolean | string;
5051
hideBorder: boolean | string;
52+
Revert: boolean | string;
5153
photoQuality: number | string;
5254
photoResize: number | string;
5355
};
@@ -87,6 +89,7 @@ async function readmeStats(req: any, res: any): Promise<any> {
8789
showItems: escapeHTML(req.query.show),
8890
hideStroke: parseBoolean(escapeHTML(req.query.hide_stroke)) || false,
8991
hideBorder: parseBoolean(escapeHTML(req.query.hide_border)) || false,
92+
Revert: parseBoolean(escapeHTML(req.query.revert)) || false,
9093
photoQuality: photoQuality,
9194
photoResize: photoResize,
9295
};

src/card.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ async function card(data: GetData, uiConfig: UiConfig): Promise<string> {
3737

3838
const isRtlDirection = parseBoolean(selectLocale.rtlDirection);
3939
const isDisabledAnimations = parseBoolean(uiConfig.disabledAnimations || uiConfig.Format === "png");
40+
const isRevert = parseBoolean(uiConfig.Revert);
4041

4142
let titleCard = defaultLocale.titleCard.split("{name}").join(data.name);
4243
if (uiConfig.Title &&
@@ -58,12 +59,13 @@ async function card(data: GetData, uiConfig: UiConfig): Promise<string> {
5859
textXPosition: isRtlDirection ? 225 : 20,
5960
dataXPosition: isRtlDirection ? 25 : 220,
6061
iconXPosition: isRtlDirection ? 235 : -5,
61-
imageXPosition: isDisabledAnimations ? 122 : 127,
62+
imageXPosition: isDisabledAnimations ? (isRevert ? 412 : 122) : (isRevert ? 417 : 127),
6263
imageYPosition: isDisabledAnimations ? 70 : 65,
63-
userXPosition: isDisabledAnimations ? 122 : 112,
64+
userXPosition: isDisabledAnimations ? (isRevert ? 412 : 122) : (isRevert ? 402 : 112),
6465
userYPosition: isDisabledAnimations ? 140 : 130,
65-
follXPosition: isDisabledAnimations ? 122 : 112,
66+
follXPosition: isDisabledAnimations ? (isRevert ? 412 : 122) : (isRevert ? 402 : 112),
6667
follYPosition: isDisabledAnimations ? 161 : 151,
68+
itemStatsXTransform: isRevert ? (isRtlDirection ? 10 : 0) : 230,
6769
};
6870

6971
const hideStroke = parseBoolean(uiConfig.hideStroke) ? `` : `stroke="#${uiConfig.strokeColor}" stroke-width="5"`;
@@ -136,7 +138,7 @@ async function card(data: GetData, uiConfig: UiConfig): Promise<string> {
136138
const cardItemsToShow = cardItems.filter(item => !item.hidden);
137139

138140
const cardItemsSVG = cardItemsToShow.map((item, index) => `
139-
<g transform="translate(230, ${15 + index * 25})">
141+
<g transform="translate(${position.itemStatsXTransform}, ${15 + index * 25})">
140142
<g class="single-item-animation" style="animation-delay: ${210 + index * 100}ms" transform="translate(25, 0)">
141143
<svg x="${position.iconXPosition}" y="0" class="icon" viewBox="0 0 16 16" version="1.1" width="16" height="16">
142144
${item.icon}

tests/card.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ describe("Test card function", () => {
4040
disabledAnimations: false,
4141
showItems: "reviews,issues_closed",
4242
hiddenItems: "forks,commits",
43+
Revert: false,
4344
photoQuality: 15,
4445
photoResize: 150,
4546
};

0 commit comments

Comments
 (0)