Skip to content

Commit d3516c2

Browse files
committed
backend: add a new fontFamily query param
1 parent 20dd844 commit d3516c2

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ None of the fields are required. Every query parameter has a default value displ
5555
| **align** | `?align=center` | left | The alignment of the badges. (`left`, `center`, `right`) |
5656
| **showBorder** | `?showBorder=false` | true | Display the border around the card or not. (`true`, `false`) |
5757
| **borderRadius** | `?borderRadius=12.5` | 4.5 | Value between 0 and 50. |
58+
| **fontFamily** | `?fontFamily=consolas` | Segoe UI | The font family of the title. If the specified family doesn't exist, the default is used. |
5859
| **fontSize** | `?fontSize=20` | 18 | The size of the title. Accepts a value between 15 and 30. |
5960
| **fontWeight** | `?fontWeight=normal` | semibold | The thickness of the title. (`thin`, `normal`, `semibold`, `bold`) |
6061
| **lineCount** | `?lineCount=2` | 1 | The number of lines you want to add to your card. |

src/cards/card-builder.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const fontWeight = z
1212
.enum(["thin", "normal", "semibold", "bold"])
1313
.catch("semibold");
1414
const fontSize = z.number().min(15).max(30).catch(18);
15+
const fontFamily = z.string().min(3).max(16).catch("Segoe UI");
1516

1617
// const numberThatAcceptsString = z.preprocess((input) => {
1718
// const processed = z
@@ -81,6 +82,11 @@ export default class CardBuilder {
8182
return this;
8283
}
8384

85+
public family(_fontFamily = "Segoe UI"): CardBuilder {
86+
this.card.setFontFamily(fontFamily.parse(_fontFamily));
87+
return this;
88+
}
89+
8490
public lines(
8591
cb: (line: number, addBadge: (b: Badge) => void) => void
8692
): CardBuilder {

src/cards/card.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default class Card {
1010
private borderRadius: number;
1111
private fontWeight: FontWeight;
1212
private fontSize: number;
13+
private fontFamily;
1314

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

@@ -21,6 +22,7 @@ export default class Card {
2122
this.borderRadius = 4.5;
2223
this.fontWeight = FontWeight.SEMIBOLD;
2324
this.fontSize = 18;
25+
this.fontFamily = "Segoe UI";
2426

2527
this.lineCount = 1;
2628
this.lines = new Map<number, Badge[]>();
@@ -102,4 +104,10 @@ export default class Card {
102104
public setFontSize = (fontSize: number): void => {
103105
this.fontSize = fontSize;
104106
};
107+
108+
public getFontFamily = (): string => this.fontFamily;
109+
110+
public setFontFamily = (fontFamily: string): void => {
111+
this.fontFamily = fontFamily;
112+
};
105113
}

src/controllers/cards-controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const getCard = async (req: Request, res: Response) => {
1212
borderRadius,
1313
fontWeight,
1414
fontSize,
15+
fontFamily,
1516
theme,
1617
} = req.query;
1718

@@ -23,6 +24,7 @@ export const getCard = async (req: Request, res: Response) => {
2324
.borderRadius(borderRadius?.toString())
2425
.fontWeight(fontWeight?.toString())
2526
.fontSize(fontSize?.toString())
27+
.family(fontFamily?.toString())
2628
.theme(theme?.toString())
2729
.lines((line, addBadge) => {
2830
// get the line query param based on the `line` argument (example: line1)

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()} ${this.card.getFontSize()}px 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
61+
.valueOf()} ${this.card.getFontSize()}px '${this.card.getFontFamily()}', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
6262
fill: ${this.card.getTheme().titleColor};
6363
}
6464
</style>

0 commit comments

Comments
 (0)