import { BRAND_COLOR, STATIC_IMAGES_URL, TRANSFORMS } from "@hey/data/constants"; import escapeHtml from "@hey/helpers/escapeHtml"; import getAccount from "@hey/helpers/getAccount"; import getAvatar from "@hey/helpers/getAvatar"; import getPostData from "@hey/helpers/getPostData"; import normalizeDescription from "@hey/helpers/normalizeDescription"; import { PostDocument, type PostFragment } from "@hey/indexer"; import type { Context } from "hono"; import { html } from "hono/html"; import generateOg from "./ogUtils"; const getPost = async (ctx: Context) => { const { slug } = ctx.req.param(); return generateOg({ buildHtml: (post: PostFragment) => { const targetPost = (post as any).__typename === "Repost" ? (post as any).repostOf : post; const { author, metadata } = targetPost as any; const { username } = getAccount(author); const postData = getPostData(metadata); const filteredContent = postData?.content || ""; const title = `${(targetPost as any).__typename} by ${username} on Hey`; const description = normalizeDescription(filteredContent, title); const postUrl = `https://hey.xyz/posts/${(post as any).slug}`; const escTitle = escapeHtml(title); const escDescription = escapeHtml(description); const asset = postData?.asset; const attachments = postData?.attachments || []; const imageUris = (() => { const list: string[] = []; if (asset?.type === "Image" && asset.uri) list.push(asset.uri); for (const att of attachments) { if (att.type === "Image" && att.uri) list.push(att.uri); } return Array.from(new Set(list)).slice(0, 4); })(); // OG/Twitter meta: prefer images; fallback to author avatar. No video support. const ogImageCandidates = imageUris.length ? imageUris : [getAvatar(author, TRANSFORMS.AVATAR_BIG)]; const ogType = "article"; const twitterCard = imageUris.length ? "summary_large_image" : "summary"; return html` ${escTitle} ${ogImageCandidates.map((img) => html``)}

${escTitle}

${escDescription}

Stats
`; }, ctx, extractData: (data) => data.post as PostFragment | null, query: PostDocument, variables: { request: { post: slug } } }); }; export default getPost;