Skip to content

Commit e793e24

Browse files
author
felix.ruf
committed
feat: adjust styling of opengraph preview
1 parent 9e0f020 commit e793e24

7 files changed

Lines changed: 83 additions & 47 deletions

File tree

data/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"basePath": "/techradar",
3-
"baseUrl": "http://localhost:3000/techradar"
3+
"baseUrl": "http://localhost:3000/techradar/"
44
}

src/app/[segment]/[id]/opengraph-image.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ImageResponse } from "next/og";
22

33
import { BaseCard } from "@/components/OpenGraph/BaseCard";
44
import { ItemInfo } from "@/components/OpenGraph/ItemInfo";
5-
import { getItem, getItems, getSegment } from "@/lib/data";
5+
import { getItem, getItems, getRing, getSegment } from "@/lib/data";
66
import { htmlToText, limitTextLength } from "@/lib/format";
77

88
export const alt = "TechRadar Open Graph Image";
@@ -23,6 +23,7 @@ export default async function OpenGraphImage({
2323
const item = getItem(res.id);
2424
const segment = getSegment(res.segment);
2525
const trimmedItemBody = limitTextLength(htmlToText(item?.body ?? ""), 100);
26+
const ring = getRing(item?.ring ?? "");
2627

2728
return new ImageResponse(
2829
(
@@ -31,7 +32,7 @@ export default async function OpenGraphImage({
3132
size={size}
3233
name={item?.title}
3334
segment={segment?.title}
34-
ring={item?.ring}
35+
ring={ring}
3536
description={trimmedItemBody}
3637
/>
3738
</BaseCard>

src/app/opengraph-image.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ImageResponse } from "next/og";
22

33
import { BaseCard } from "@/components/OpenGraph/BaseCard";
44
import { getAppName, getLabel } from "@/lib/data";
5+
import { limitTextLength } from "@/lib/format";
56

67
export const alt = "TechRadar Open Graph Image";
78
export const size = {
@@ -34,7 +35,7 @@ export default async function OpenGraphImage() {
3435
width: `${size.width}px`,
3536
}}
3637
>
37-
{getAppName()}
38+
{limitTextLength(getAppName(), 60)}
3839
</h2>
3940
<p
4041
style={{
@@ -47,7 +48,7 @@ export default async function OpenGraphImage() {
4748
fontSize: 32,
4849
}}
4950
>
50-
{getLabel("metaDescription")}
51+
{limitTextLength(getLabel("metaDescription"), 150)}
5152
</p>
5253
</div>
5354
</BaseCard>

src/components/OpenGraph/BackgroundImage.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import React, { FC } from "react";
22

3-
import { Blip } from "../Radar/Blip";
4-
53
import { getChartConfig } from "@/lib/data";
64
import { Flag, Item, Ring, Segment } from "@/lib/types";
75

@@ -21,7 +19,6 @@ export const BackgroundImage: FC<BackgroundImageProps> = ({
2119
segments = [],
2220
rings = [],
2321
items = [],
24-
className,
2522
}) => {
2623
const viewBoxSize = size;
2724
const center = size / 2;
@@ -80,12 +77,6 @@ export const BackgroundImage: FC<BackgroundImageProps> = ({
8077
const startAngle = (position - 1) * angleIncrement;
8178
const endAngle = startAngle + angleIncrement;
8279

83-
const cx = (startAngle + endAngle) / 2 > 180 ? 1 : 0;
84-
const cy =
85-
(startAngle + endAngle) / 2 > 90 && (startAngle + endAngle) / 2 < 270
86-
? 1
87-
: 0;
88-
8980
if (numSegments == 1)
9081
return (
9182
<circle
@@ -160,12 +151,10 @@ export const BackgroundImage: FC<BackgroundImageProps> = ({
160151
/>
161152
);
162153
}
163-
// return <Blip color={segment.color} x={x} y={y} flag={item.flag} />;
164154
};
165155

166156
return (
167157
<svg
168-
className={className}
169158
width={viewBoxSize}
170159
height={viewBoxSize}
171160
viewBox={`0 0 ${viewBoxSize} ${viewBoxSize}`}

src/components/OpenGraph/BaseCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
getSegments,
1010
getTags,
1111
} from "@/lib/data";
12-
import { Item, Ring, Segment } from "@/lib/types";
12+
import { Segment } from "@/lib/types";
1313
import { listContainsAny } from "@/lib/utils";
1414

1515
interface BaseCardProps {
Lines changed: 69 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { FC } from "react";
22

3-
import { getAppName } from "@/lib/data";
4-
import { formatTitle, formatTitleWithMissing } from "@/lib/format";
3+
import { getAppName, getColors } from "@/lib/data";
4+
import { formatTitleWithMissing, limitTextLength } from "@/lib/format";
5+
import { Ring } from "@/lib/types";
56

67
interface ItemInfoProps {
78
size: { height: number; width: number };
89
name?: string;
910
segment?: string;
10-
ring?: string;
11+
ring?: Ring;
1112
description?: string;
1213
}
1314

@@ -18,6 +19,11 @@ export const ItemInfo: FC<ItemInfoProps> = ({
1819
ring,
1920
description,
2021
}) => {
22+
const colors = getColors();
23+
const descTextSize = 28;
24+
const descLineHeight = 32;
25+
const descPaddingVert = 20;
26+
2127
return (
2228
<div
2329
style={{
@@ -26,40 +32,75 @@ export const ItemInfo: FC<ItemInfoProps> = ({
2632
width: "100%",
2733
height: "100%",
2834
flex: 1,
29-
padding: 50,
35+
padding: "30px 50px",
3036
}}
3137
>
3238
<h2
3339
style={{
3440
display: "block",
3541
fontWeight: "bold",
36-
width: `${size.width * 0.65}px`,
37-
}}
38-
>
39-
{formatTitleWithMissing(name, getAppName())}
40-
</h2>
41-
<span
42-
style={{
43-
fontSize: 32,
44-
width: `${size.width * 0.65}px`,
45-
flex: 1,
46-
}}
47-
>
48-
{formatTitleWithMissing(segment, ring)}
49-
</span>
50-
<p
51-
style={{
52-
display: "block",
53-
textOverflow: "ellipsis",
54-
overflow: "hidden",
55-
whiteSpace: "wrap",
56-
height: "17%",
5742
width: `${size.width * 0.75}px`,
58-
fontSize: 32,
5943
}}
6044
>
61-
{description}
62-
</p>
45+
{limitTextLength(formatTitleWithMissing(name, getAppName()), 50)}
46+
</h2>
47+
{segment && (
48+
<span
49+
style={{
50+
fontSize: 32,
51+
width: `${size.width * 0.65}px`,
52+
flex: 1,
53+
}}
54+
>
55+
{limitTextLength(segment, 80)}
56+
</span>
57+
)}
58+
{description && (
59+
<p
60+
style={{
61+
display: "flex",
62+
maxHeight: `${48 + 2 * descPaddingVert + 2 * descLineHeight}px`,
63+
width: `${size.width * 0.75}px`,
64+
padding: `${24 + descPaddingVert}px 24px`,
65+
borderRadius: "12px",
66+
backgroundColor: colors.foreground,
67+
whiteSpace: "wrap",
68+
textAlign: "left",
69+
fontSize: `${descTextSize}px`,
70+
lineHeight: `${descLineHeight}px`,
71+
color: colors.text,
72+
}}
73+
>
74+
{limitTextLength(description, 100)}
75+
{ring && (
76+
<div
77+
style={{
78+
display: "flex",
79+
position: "absolute",
80+
top: `-${descPaddingVert}px`,
81+
left: "32px",
82+
}}
83+
>
84+
<span
85+
style={{
86+
borderRadius: "100px",
87+
background: ring.color,
88+
color: colors.content,
89+
width: "auto",
90+
padding: "12px 32px",
91+
textTransform: "uppercase",
92+
alignItems: "center",
93+
fontSize: "28px",
94+
lineHeight: "28px",
95+
flexShrink: 0,
96+
}}
97+
>
98+
{ring.title}
99+
</span>
100+
</div>
101+
)}
102+
</p>
103+
)}
63104
</div>
64105
);
65106
};

src/components/OpenGraph/SegmentInfo.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FC } from "react";
22

33
import { getAppName } from "@/lib/data";
4+
import { formatTitleWithMissing, limitTextLength } from "@/lib/format";
45
import { Segment } from "@/lib/types";
56

67
interface SegmentProps {
@@ -28,7 +29,10 @@ export const SegmentInfo: FC<SegmentProps> = ({ segment, size }) => {
2829
width: `${size.width * 0.65}px`,
2930
}}
3031
>
31-
{segment.title} | {getAppName()}
32+
{limitTextLength(
33+
formatTitleWithMissing(segment.title, getAppName()),
34+
60,
35+
)}
3236
</h2>
3337
<p
3438
style={{
@@ -41,7 +45,7 @@ export const SegmentInfo: FC<SegmentProps> = ({ segment, size }) => {
4145
fontSize: 32,
4246
}}
4347
>
44-
{segment.description}
48+
{limitTextLength(segment.description, 150)}
4549
</p>
4650
</div>
4751
);

0 commit comments

Comments
 (0)