Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
1import {
2 BRAND_COLOR,
3 STATIC_IMAGES_URL,
4 TRANSFORMS
5} from "@hey/data/constants";
6import escapeHtml from "@hey/helpers/escapeHtml";
7import { default as getAccountData } from "@hey/helpers/getAccount";
8import getAvatar from "@hey/helpers/getAvatar";
9import normalizeDescription from "@hey/helpers/normalizeDescription";
10import { AccountDocument, type AccountFragment } from "@hey/indexer";
11import type { Context } from "hono";
12import { html } from "hono/html";
13import generateOg from "./ogUtils";
14
15const getAccount = async (ctx: Context) => {
16 const { username } = ctx.req.param();
17
18 return generateOg({
19 buildHtml: (account: AccountFragment) => {
20 const { name, link } = getAccountData(account);
21 const title = `${name} (${username}) on Hey`;
22 const description = normalizeDescription(account?.metadata?.bio, title);
23 const avatar = getAvatar(account, TRANSFORMS.AVATAR_BIG);
24
25 const escTitle = escapeHtml(title);
26 const escDescription = escapeHtml(description);
27 const escName = escapeHtml(name);
28 const escUsername = escapeHtml(username);
29
30 return html`
31 <html>
32 <head>
33 <meta charSet="utf-8" />
34 <meta name="viewport" content="width=device-width" />
35 <meta http-equiv="content-language" content="en-US" />
36 <meta name="theme-color" content="${BRAND_COLOR}" />
37 <title>${escTitle}</title>
38 <meta name="description" content="${escDescription}" />
39 <meta property="og:title" content="${escTitle}" />
40 <meta property="og:description" content="${escDescription}" />
41 <meta property="og:type" content="profile" />
42 <meta property="og:site_name" content="Hey" />
43 <meta property="og:url" content="https://hey.xyz${link}" />
44 <meta property="og:image" content="${avatar}" />
45 <meta property="og:logo" content="${STATIC_IMAGES_URL}/app-icon/0.png" />
46 <meta name="twitter:card" content="summary" />
47 <meta name="twitter:title" content="${escTitle}" />
48 <meta name="twitter:description" content="${escDescription}" />
49 <meta name="twitter:image" content="${avatar}" />
50 <meta name="twitter:site" content="@heydotxyz" />
51 <link rel="icon" href="https://hey.xyz/favicon.ico" />
52 <link rel="canonical" href="https://hey.xyz${link}" />
53 </head>
54 <body>
55 <img src="${avatar}" alt="${escName}" height="100" width="100" />
56 <h1>${escName || username}</h1>
57 <h2>${escUsername}</h2>
58 <h3>${escDescription}</h3>
59 </body>
60 </html>
61 `;
62 },
63 ctx,
64 extractData: (data) => data.account,
65 query: AccountDocument,
66 variables: { request: { username: { localName: username } } }
67 });
68};
69
70export default getAccount;