diff --git a/app/(v2)/tags/[serial]/opengraph-image.tsx b/app/(v2)/tags/[serial]/opengraph-image.tsx new file mode 100644 index 000000000..3fb84cc18 --- /dev/null +++ b/app/(v2)/tags/[serial]/opengraph-image.tsx @@ -0,0 +1,116 @@ +import { ImageResponse } from "next/og"; + +import { graphql } from "~/gql"; +import { makeGraphQLClient } from "~/gql/fetch"; +import { loadGoogleFont } from "~/utils/loadGoogleFonts"; + +export const size = { + width: 960, + height: 540, +}; +export const contentType = "image/png"; +export const revalidate = 86400; + +export default async function og({ params }: { params: { serial: string } }) { + const result = await makeGraphQLClient() + .request( + graphql(` + query TagPage_OGImage($serial: Int!) { + findTagBySerial(serial: $serial) { + name + serial + taggedVideosByOffset(input: { offset: 0, take: 24 }) { + nodes { + video { + thumbnailUrl + } + } + } + } + } + `), + { serial: parseInt(params.serial, 10) } + ) + .then((data) => data.findTagBySerial); + + if (!result) return new Response("Video not found", { status: 404 }); + + const { name, serial, taggedVideosByOffset } = result; + const urltext = `otomadb.com/tags/${serial}`; + + const notoserif = await loadGoogleFont({ + family: "Noto Serif JP", + weight: 700, + text: name, + }); + const spacemono = await loadGoogleFont({ + family: "Space Mono", + weight: 400, + text: urltext, + }); + + return new ImageResponse( + ( +
+
+
+ {name} +
+
+ {urltext} +
+
+
+ ), + { + ...size, + fonts: [ + { + name: "Noto Serif JP", + data: notoserif, + style: "normal", + weight: 700, + }, + { + name: "Space Mono", + data: spacemono, + style: "normal", + weight: 400, + }, + ], + } + ); +} diff --git a/app/(v2)/tags/[serial]/twitter-image.tsx b/app/(v2)/tags/[serial]/twitter-image.tsx new file mode 100644 index 000000000..3e3cf1f46 --- /dev/null +++ b/app/(v2)/tags/[serial]/twitter-image.tsx @@ -0,0 +1,4 @@ +import og from "./opengraph-image"; +export { contentType, revalidate, size } from "./opengraph-image"; + +export default og;