Skip to content

Commit 604b4b4

Browse files
committed
hotfix: more thoroughly fallback to announcement on missing og data
1 parent dd4cadc commit 604b4b4

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

app/[locale]/next-data/og/route.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,20 @@ export const GET = async (request: Request) => {
1717
const hasTitle = searchParams.has('title');
1818
const title = hasTitle ? searchParams.get('title')?.slice(0, 100) : undefined;
1919

20-
//?type=<type>
21-
const type = searchParams.get('type') ?? 'announcement';
20+
//?type=<type> - if undefined default to announcement
21+
const typeParam = searchParams.get('type') ?? 'announcement';
2222

2323
const typeAttributes: { [key: string]: string } = {
2424
announcement: tailwindConfig.theme.colors.green['700'],
2525
release: tailwindConfig.theme.colors.info['600'],
2626
vulnerability: tailwindConfig.theme.colors.warning['600'],
2727
};
2828

29-
const gridBackground = `radial-gradient(circle, ${hexToRGBA(typeAttributes[type])}, transparent)`;
29+
// use the mapped value, or if not found use announcement
30+
const type =
31+
typeAttributes[typeParam] ?? tailwindConfig.theme.colors.green['700'];
32+
33+
const gridBackground = `radial-gradient(circle, ${hexToRGBA(type)}, transparent)`;
3034

3135
return new ImageResponse(
3236
(

util/hexToRGBA.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const hexToRGBA = (hex: string, alpha = 0.9) => {
1+
export const hexToRGBA = (hex: string = '', alpha = 0.9) => {
22
hex = hex.replace(/^#/, '');
33

44
const bigint = parseInt(hex, 16);

0 commit comments

Comments
 (0)