Skip to content

Commit 25d32df

Browse files
committed
backend(Card): added a new ontSize query param
1 parent 6d57a06 commit 25d32df

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
<br>
1919

2020
<div align="center">
21-
<a href="https://github-readme-tech-stack.vercel.app/api/cards?theme=github_dark&lineCount=2&line1=node.js,node.js,0;typescript,typescript,0;express,express,0&line2=html5,html,0;react,react,0;tailwindcss,tailwind,0&title=This%20Project%27s%20Tech%20Stack">
22-
<img src="https://github-readme-tech-stack.vercel.app/api/cards?theme=github_dark&lineCount=2&line1=node.js,node.js,0;typescript,typescript,0;express,express,0&line2=html5,html,0;react,react,0;tailwindcss,tailwind,0&title=This%20Project%27s%20Tech%20Stack" title="Tech Stack">
21+
<a href="https://github-readme-tech-stack.vercel.app/api/cards?theme=github_dark&lineCount=2&line1=node.js,node.js,0;typescript,typescript,0;express,express,61DAFB&line2=html5,html,0;react,react,0;tailwindcss,tailwind,0&title=This%20Project%27s%20Tech%20Stack">
22+
<img src="https://github-readme-tech-stack.vercel.app/api/cards?theme=github_dark&lineCount=2&line1=node.js,node.js,0;typescript,typescript,0;express,express,61DAFB&line2=html5,html,0;react,react,0;tailwindcss,tailwind,0&title=This%20Project%27s%20Tech%20Stack" title="Tech Stack">
2323
</a>
2424
</div>
2525

@@ -58,6 +58,7 @@ With this site, you can customize your card.
5858
| **align** | `?align=center` | left | The alignment of the badges. (`left`, `center`, `right`) |
5959
| **showBorder** | `?showBorder=false` | true | Display the border around the card or not. (`true`, `false`) |
6060
| **borderRadius** | `?borderRadius=12.5` | 4.5 | Value between 0 and 50. |
61+
| **fontSize** | `?fontSize=20` | 18 | The size of the title. Accepts a value between 15 and 30. |
6162
| **fontWeight** | `?fontWeight=normal` | semibold | The thickness of the title. (`thin`, `normal`, `semibold`, `bold`) |
6263
| **lineCount** | `?lineCount=2` | 1 | The number of lines you want to add to your card. |
6364
| **line{n}** | `?line1=typescript,typescript,2D79C7` | - | The current line of the badge, where {n} is a number. *`(1 <= n <= lineCount)`* |

src/cards/card.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default class Card {
99
private showBorder: boolean;
1010
private borderRadius: number;
1111
private fontWeight: FontWeight;
12+
private fontSize: number;
1213

1314
private lines: Map<number, Badge[]>;
1415

@@ -19,6 +20,7 @@ export default class Card {
1920
this.showBorder = true;
2021
this.borderRadius = 4.5;
2122
this.fontWeight = FontWeight.SEMIBOLD;
23+
this.fontSize = 18;
2224

2325
this.lineCount = 1;
2426
this.lines = new Map<number, Badge[]>();
@@ -94,4 +96,10 @@ export default class Card {
9496
break;
9597
}
9698
};
99+
100+
public getFontSize = (): number => this.fontSize;
101+
102+
public setFontSize = (fontSize: number): void => {
103+
this.fontSize = fontSize;
104+
};
97105
}

src/controllers/cards-controller.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import SvgGenerator from "../svg/svg-generator";
55
import {
66
validateAlign,
77
validateBorderRadius,
8+
validateFontSize,
89
validateLine,
910
validateLineCount,
1011
} from "../utils/validator";
@@ -19,6 +20,7 @@ export const getCard = async (req: Request, res: Response) => {
1920
const showBorder = req.query.showBorder?.toString() || "true";
2021
const borderRadius = req.query.borderRadius?.toString() || "4.5";
2122
const fontWeight = req.query.fontWeight?.toString() || "semibold";
23+
const fontSize = req.query.fontSize?.toString() || "18";
2224

2325
card.setTitle(title);
2426
card.setTheme(getThemeByName(theme));
@@ -27,6 +29,7 @@ export const getCard = async (req: Request, res: Response) => {
2729
card.setShowBorder(showBorder !== "false");
2830
card.setBorderRadius(validateBorderRadius(borderRadius));
2931
card.setFontWeight(fontWeight);
32+
card.setFontSize(validateFontSize(fontSize));
3033

3134
// run a loop card.getLineCount() times
3235
for (let i = 1; i <= card.getLineCount(); i++) {

src/svg/svg-generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default class SvgGenerator {
5858
.header {
5959
font: ${this.card
6060
.getFontWeight()
61-
.valueOf()} 18px 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
61+
.valueOf()} ${this.card.getFontSize()}px 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
6262
fill: ${this.card.getTheme().titleColor};
6363
}
6464
</style>

src/utils/validator.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ export const validateBorderRadius = (lineCount: string): number => {
4040
return num > 50 || num < 0 ? 4.5 : num;
4141
};
4242

43+
/**
44+
* Validates the font size.
45+
*
46+
* @param {number} fontSize The raw fontSize.
47+
* @returns {number} A valid fontSize.
48+
*/
49+
export const validateFontSize = (fontSize: string): number => {
50+
const num = parseInt(fontSize);
51+
52+
// it's not a number
53+
if (isNaN(num)) {
54+
return 18;
55+
}
56+
57+
return num > 30 || num < 15 ? 18 : num;
58+
};
59+
4360
/**
4461
* Validates the given align.
4562
*

0 commit comments

Comments
 (0)