Skip to content

Commit 7c4d882

Browse files
committed
backend(card): add hideTitle query parameter
1 parent 1c8412a commit 7c4d882

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ None of the fields are required. Every query parameter has a default value displ
6464
| **theme** | `?theme=github_dark` | github | The theme of the card. You can browse between the themes [here](docs/THEMES.md). |
6565
| **align** | `?align=center` | left | The alignment of the badges. (`left`, `center`, `right`) |
6666
| **showBorder** | `?showBorder=false` | true | Display the border around the card or not. (`true`, `false`) |
67+
| **hideTitle** | `?hideTitle=true` | false | Display the title of the card or not. (`true`, `false`) |
6768
| **hideBg** | `?hideBg=true` | false | If true, sets the background to transparent. (`true`, `false`) |
6869
| **borderRadius** | `?borderRadius=12.5` | 4.5 | Number between 0 and 50. |
6970
| **fontFamily** | `?fontFamily=consolas` | Segoe UI | The font family of the title. If the specified family doesn't exist, the default is used. |

src/cards/card-builder.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ export default class CardBuilder {
6565
return this;
6666
}
6767

68+
public hideTitle(_hideTitle = "false"): CardBuilder {
69+
this.card.setHideTitle(_hideTitle === "true");
70+
return this;
71+
}
72+
6873
public borderRadius(_borderRadius = "4.5"): CardBuilder {
6974
this.card.setBorderRadius(borderRadius.parse(Number(_borderRadius)));
7075
return this;

src/cards/card.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default class Card {
1313
private fontFamily: string;
1414
private gap: number;
1515
private lineHeight: number;
16+
private hideTitle: boolean;
1617

1718
private lines: Map<number, Badge[]>;
1819

@@ -27,6 +28,7 @@ export default class Card {
2728
this.fontFamily = "Segoe UI";
2829
this.gap = 10;
2930
this.lineHeight = 7;
31+
this.hideTitle = false;
3032

3133
this.lineCount = 1;
3234
this.lines = new Map<number, Badge[]>();
@@ -126,4 +128,10 @@ export default class Card {
126128
public setLineHeight = (lineHeight: number): void => {
127129
this.lineHeight = lineHeight;
128130
};
131+
132+
public getHideTitle = (): boolean => this.hideTitle;
133+
134+
public setHideTitle = (hideTitle: boolean): void => {
135+
this.hideTitle = hideTitle;
136+
};
129137
}

src/controllers/cards-controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ export const getCard = async (req: Request, res: Response) => {
2222
badge,
2323
titleColor,
2424
hideBg,
25+
hideTitle,
2526
} = req.query;
2627

2728
const card = new CardBuilder()
2829
.title(title?.toString())
2930
.lineCount(lineCount?.toString())
3031
.align(align?.toString())
3132
.border(showBorder?.toString())
33+
.hideTitle(hideTitle?.toString())
3234
.borderRadius(borderRadius?.toString())
3335
.fontWeight(fontWeight?.toString())
3436
.fontSize(fontSize?.toString())

src/svg/svg-generator.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export default class SvgGenerator {
2020
// the base (line == 1) height is 100
2121
// each additional line increases the height by this.lineHeight
2222
this.height = 100 + (card.getLineCount() - 1) * this.lineHeight;
23+
24+
if (this.card.getHideTitle()) {
25+
this.height -= this.card.getFontSize() + 5;
26+
}
2327
}
2428

2529
/**
@@ -52,9 +56,13 @@ export default class SvgGenerator {
5256
stroke-opacity="${this.card.getShowBorder() ? 1 : 0}"
5357
/>
5458
55-
<g transform="translate(25, 35)">
56-
<text x="0" y="0" class="header">${this.card.getTitle()}</text>
57-
</g>
59+
${
60+
this.card.getHideTitle()
61+
? ""
62+
: `<g transform="translate(25, 35)">
63+
<text x="0" y="0" class="header">${this.card.getTitle()}</text>
64+
</g>`
65+
}
5866
5967
${await this.generateLines()}
6068
@@ -89,7 +97,11 @@ export default class SvgGenerator {
8997
): Promise<string> => {
9098
// the first line is this.lineHeight
9199
// each additional line increases this by this.lineHeight
92-
const translateY = 35 + (lineNumber - 1) * this.lineHeight;
100+
let translateY = 35 + (lineNumber - 1) * this.lineHeight;
101+
102+
if (this.card.getHideTitle()) {
103+
translateY -= this.card.getFontSize() + this.card.getFontSize() / 3;
104+
}
93105

94106
let icons = "";
95107
let leftPadding = 0;

0 commit comments

Comments
 (0)