Skip to content

Commit cff2583

Browse files
committed
Truncate description
1 parent 464decb commit cff2583

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

apps/page/components/seo-tags.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,16 @@ const SeoTags = ({
2424
}) => {
2525
const pageUrl = useMemo(() => getPageUrl(page, settings), [page, settings]);
2626

27+
const truncatedDescription = useMemo(() => {
28+
if (!description) return null;
29+
return description.length > 150
30+
? description.substring(0, 150) + "..."
31+
: description;
32+
}, [description]);
33+
2734
const ogImageUrl = useMemo(
28-
() => getOgUrl(page, settings, title, description),
29-
[page, settings, title, description]
35+
() => getOgUrl(page, settings, title, truncatedDescription),
36+
[page, settings, title, truncatedDescription]
3037
);
3138

3239
return (
@@ -46,7 +53,7 @@ const SeoTags = ({
4653
openGraph={{
4754
url: url || pageUrl,
4855
title: title ?? page?.title,
49-
description: description ?? page?.description ?? "",
56+
description: truncatedDescription ?? page?.description ?? "",
5057
images: [
5158
{
5259
url: ogImageUrl,

apps/page/lib/url.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,16 @@ export function getOgUrl(
4141
const pageUrl = getPageUrl(page, settings);
4242

4343
if (title?.length && description?.length) {
44-
const contentTruncated =
45-
description.length > 350
46-
? description.substring(0, 350) + "..."
47-
: description;
48-
4944
return `${pageUrl}/api/og?title=${encodeURIComponent(
5045
page?.title
5146
)}&body=${encodeURIComponent(title)}&content=${encodeURIComponent(
52-
contentTruncated
47+
description
5348
)}${settings?.page_logo ? "&logo=" + settings?.page_logo : ""}`;
5449
}
5550

5651
return `${pageUrl}/api/og?title=${encodeURIComponent(
5752
page?.title
58-
)}&body=${encodeURIComponent(description ?? page.description ?? "")}${
59-
settings?.page_logo ? "&logo=" + settings?.page_logo : ""
60-
}`;
53+
)}&body=${encodeURIComponent(
54+
title ?? description ?? page.description ?? ""
55+
)}${settings?.page_logo ? "&logo=" + settings?.page_logo : ""}`;
6156
}

0 commit comments

Comments
 (0)