Skip to content

Commit 271d309

Browse files
committed
fix: revert opengraph image changes
1 parent 6a25aa3 commit 271d309

File tree

6 files changed

+58
-41
lines changed

6 files changed

+58
-41
lines changed

app/(cms)/opengraph-image.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import OpengraphImage from "components/opengraph-image";
22
import { getPage } from "lib/shopware";
33

4-
export default async function Image({ params }: { params: { page: string } }) {
5-
const { page: pageParamName } = await params;
6-
const page = await getPage(pageParamName);
7-
const title = page ? page.seo?.title || page.title : "";
4+
export const runtime = "edge";
5+
6+
export default async function Image({
7+
params,
8+
}: {
9+
params?: { page?: string };
10+
}) {
11+
const pageParamName = params?.page || "";
12+
const page = pageParamName !== "" ? await getPage(pageParamName) : null;
13+
const title = page ? page.seo?.title || page.title || "" : "";
814

915
return await OpengraphImage({ title });
1016
}

app/opengraph-image.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import OpengraphImage from "components/opengraph-image";
22

3+
export const runtime = "edge";
4+
35
export default async function Image() {
46
return await OpengraphImage();
57
}

app/product/[...handle]/page.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ProductProvider } from "components/product/product-context";
88
import { ProductDescription } from "components/product/product-description";
99
import { HIDDEN_PRODUCT_TAG } from "lib/constants";
1010
import { getProduct, getProductRecommendations } from "lib/shopware";
11-
import { Image } from "lib/shopware/types";
11+
import type { Image } from "lib/shopware/types";
1212
import Link from "next/link";
1313
import { Suspense } from "react";
1414

@@ -130,7 +130,6 @@ async function RelatedProducts({ id }: { id: string }) {
130130
<Link
131131
className="relative h-full w-full"
132132
prefetch={true}
133-
role="link"
134133
href={`/product/${product.path}`}
135134
>
136135
<GridTileImage

app/search/(collection)/[...collection]/page.tsx

+31-26
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1-
import { Metadata } from 'next';
2-
import { notFound } from 'next/navigation';
1+
import type { Metadata } from "next";
2+
import { notFound } from "next/navigation";
33

4-
import Pagination from 'components/collection/pagination';
5-
import Grid from 'components/grid';
6-
import ProductGridItems from 'components/layout/product-grid-items';
7-
import Collections from 'components/layout/search/collections';
8-
import FilterList from 'components/layout/search/filter';
4+
import Pagination from "components/collection/pagination";
5+
import Grid from "components/grid";
6+
import ProductGridItems from "components/layout/product-grid-items";
7+
import Collections from "components/layout/search/collections";
8+
import FilterList from "components/layout/search/filter";
99

10-
import { defaultSort, sorting } from 'lib/constants';
11-
import { getCollection, getCollectionProducts } from 'lib/shopware';
12-
import { transformHandle } from 'lib/shopware/transform';
10+
import { defaultSort, sorting } from "lib/constants";
11+
import { getCollection, getCollectionProducts } from "lib/shopware";
12+
import { transformHandle } from "lib/shopware/transform";
1313

1414
export async function generateMetadata({
15-
params
15+
params,
1616
}: {
1717
params: Promise<{ collection: string }>;
1818
}): Promise<Metadata> {
1919
const { collection: collectionParamName } = await params;
2020

2121
// see https://github.com/facebook/react/issues/25994
22-
const collectionName = decodeURIComponent(transformHandle(collectionParamName ?? ''));
23-
if (collectionName.includes('.js.map')) {
22+
const collectionName = decodeURIComponent(
23+
transformHandle(collectionParamName ?? ""),
24+
);
25+
if (collectionName.includes(".js.map")) {
2426
return {};
2527
}
2628

@@ -31,47 +33,50 @@ export async function generateMetadata({
3133
return {
3234
title: collection.seo?.title || collection.title,
3335
description:
34-
collection.seo?.description || collection.description || `${collection.title} products`,
36+
collection.seo?.description ||
37+
collection.description ||
38+
`${collection.title} products`,
3539
openGraph: collection.featuredImage
3640
? {
3741
images: [
3842
{
39-
url: collection.featuredImage
40-
}
41-
]
43+
url: collection.featuredImage,
44+
},
45+
],
4246
}
43-
: null
47+
: null,
4448
};
4549
}
4650

4751
export default async function CategoryPage({
4852
params,
49-
searchParams
53+
searchParams,
5054
}: {
5155
params: Promise<{ collection: string }>;
5256
searchParams?: Promise<{ [key: string]: string | string[] | undefined }>;
5357
}) {
5458
const { collection } = await params;
5559
const { sort, page } = (await searchParams) as { [key: string]: string };
56-
const { sortKey, reverse } = sorting.find((item) => item.slug === sort) || defaultSort;
60+
const { sortKey, reverse } =
61+
sorting.find((item) => item.slug === sort) || defaultSort;
5762

5863
// see https://github.com/facebook/react/issues/25994
59-
const collectionName = decodeURIComponent(transformHandle(collection ?? ''));
60-
if (collectionName.includes('.js.map')) {
64+
const collectionName = decodeURIComponent(transformHandle(collection ?? ""));
65+
if (collectionName.includes(".js.map")) {
6166
return null;
6267
}
6368

6469
const { products, total, limit } = await getCollectionProducts({
6570
collection: collectionName,
66-
page: page ? parseInt(page) : 1,
71+
page: page ? Number.parseInt(page) : 1,
6772
sortKey,
68-
reverse
73+
reverse,
6974
});
7075

7176
return (
7277
<section>
7378
{products.length === 0 ? (
74-
<p className="py-3 text-lg">{`No products found in this collection`}</p>
79+
<p className="py-3 text-lg">No products found in this collection</p>
7580
) : (
7681
<div className="mx-auto flex max-w-screen-2xl flex-col gap-8 px-4 pb-4 text-black md:flex-row dark:text-white">
7782
<div className="order-first w-full flex-none md:max-w-[125px]">
@@ -89,7 +94,7 @@ export default async function CategoryPage({
8994
<Pagination
9095
itemsPerPage={limit}
9196
itemsTotal={total}
92-
currentPage={page ? parseInt(page) - 1 : 0}
97+
currentPage={page ? Number.parseInt(page) - 1 : 0}
9398
/>
9499
</nav>
95100
) : null}
+11-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import OpengraphImage from "components/opengraph-image";
22
import { getCollection } from "lib/shopware";
33

4+
export const runtime = "edge";
5+
46
export default async function Image({
57
params,
68
}: {
7-
params: { collection: string };
9+
params: { collection: string[] };
810
}) {
9-
const collection = await getCollection(params.collection);
10-
const title = collection?.seo?.title || collection?.title;
11+
const collectionPath = params.collection
12+
? Array.isArray(params.collection)
13+
? params.collection.join("/")
14+
: ""
15+
: "";
16+
const collection =
17+
collectionPath !== "" ? await getCollection(collectionPath) : null;
18+
const title = collection?.seo?.title || collection?.title || "";
1119

1220
return await OpengraphImage({ title });
1321
}

components/opengraph-image.tsx

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { ImageResponse } from "next/og";
22
import LogoIcon from "./icons/logo";
3-
import { join } from "path";
4-
import { readFile } from "fs/promises";
53

64
export type Props = {
75
title?: string;
@@ -17,9 +15,6 @@ export default async function OpengraphImage(
1715
...props,
1816
};
1917

20-
const file = await readFile(join(process.cwd(), "./fonts/Inter-Bold.ttf"));
21-
const font = Uint8Array.from(file).buffer;
22-
2318
return new ImageResponse(
2419
(
2520
<div tw="flex h-full w-full flex-col items-center justify-center bg-black">
@@ -35,7 +30,9 @@ export default async function OpengraphImage(
3530
fonts: [
3631
{
3732
name: "Inter",
38-
data: font,
33+
data: await fetch(
34+
new URL("../fonts/Inter-Bold.ttf", import.meta.url),
35+
).then((res) => res.arrayBuffer()),
3936
style: "normal",
4037
weight: 700,
4138
},

0 commit comments

Comments
 (0)