Skip to content

Commit 9d728e7

Browse files
committed
backend(themes): add a new 'bg' query param
1 parent e9c4ff0 commit 9d728e7

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/cards/card-builder.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { z } from "zod";
2+
import { isHexColor } from "../utils/validator";
23
import Card from "./card";
34
import { getThemeByName } from "./themes";
45
import { Badge } from "./types";
@@ -99,6 +100,17 @@ export default class CardBuilder {
99100
return this;
100101
}
101102

103+
public bg(bgColor = ""): CardBuilder {
104+
if (isHexColor(bgColor)) {
105+
this.card.setTheme({
106+
...this.card.getTheme(),
107+
backgroundColor: bgColor,
108+
});
109+
}
110+
111+
return this;
112+
}
113+
102114
public lines(
103115
cb: (line: number, addBadge: (b: Badge) => void) => void
104116
): CardBuilder {

src/controllers/cards-controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const getCard = async (req: Request, res: Response) => {
1717
gap,
1818
lineHeight,
1919
width,
20+
bg,
2021
} = req.query;
2122

2223
const card = new CardBuilder()
@@ -39,6 +40,7 @@ export const getCard = async (req: Request, res: Response) => {
3940
addBadge(b)
4041
);
4142
})
43+
.bg(bg?.toString())
4244
.build();
4345

4446
res.setHeader("Content-Type", "image/svg+xml");

0 commit comments

Comments
 (0)