| 1 | import type { ReactNode, SVGProps } from "react"; |
| 2 | |
| 3 | export const SITE_URL = |
| 4 | |
| 5 | export const AVATAR_URL = |
| 6 | |
| 7 | export const OG_SIZE = |
| 8 | |
| 9 | export const OG_NAME = |
| 10 | export const OG_HANDLE = |
| 11 | |
| 12 | export const LOCALE_NAMES: |
| 13 | en: "English", |
| 14 | de: "Deutsch", |
| 15 | }; |
| 16 | |
| 17 | export type OgFont |
| 18 | name: string |
| 19 | data: ArrayBuffer |
| 20 | weight: 400 |
| 21 | style: "normal |
| 22 | }; |
| 23 | |
| 24 | export function truncate(text |
| 25 | if (text.length |
| 26 | return text.slice |
| 27 | } |
| 28 | |
| 29 | export function formatDate(date |
| 30 | const d = |
| 31 | const pad = |
| 32 | return `${pad( |
| 33 | } |
| 34 | |
| 35 | async function loadGoogleFont( |
| 36 | family: string, |
| 37 | weight: number, |
| 38 | text: string, |
| 39 | ): Promise<ArrayBuffer |
| 40 | const url = |
| 41 | text, |
| 42 | )}`; |
| 43 | const css = |
| 44 | const resource = |
| 45 | /src: url\((.+?) |
| 46 | ); |
| 47 | if (!resource) |
| 48 | const res = |
| 49 | if (!res.ok |
| 50 | return res.arrayBuffer |
| 51 | } |
| 52 | |
| 53 | function toBase64(buffer: |
| 54 | const bytes = |
| 55 | let binary = |
| 56 | for (let i |
| 57 | binary += String. |
| 58 | return btoa(binary |
| 59 | } |
| 60 | |
| 61 | async function loadAvatar() |
| 62 | const res = |
| 63 | if (!res.ok |
| 64 | const type = |
| 65 | return `data:${type |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Google serves a subsetted font, so every glyph we render has to be listed in |
| 70 | * the request. `boldText`/`regularText` are the concatenated strings of the |
| 71 | * card, per weight. |
| 72 | */ |
| 73 | export async function loadOgAssets |
| 74 | return Promise.all |
| 75 | Promise.all([ |
| 76 | loadGoogleFont("Hanken+Grotesk", |
| 77 | name: "Hanken Grotesk", |
| 78 | data, |
| 79 | weight: 700 as const |
| 80 | style: "normal" as |
| 81 | })), |
| 82 | loadGoogleFont("Hanken+Grotesk", |
| 83 | name: "Hanken Grotesk", |
| 84 | data, |
| 85 | weight: 400 as const |
| 86 | style: "normal" as |
| 87 | })), |
| 88 | ]).catch(() => |
| 89 | loadAvatar().catch(() |
| 90 | ]); |
| 91 | } |
| 92 | |
| 93 | export function OgFrame(props |
| 94 | avatar: string |
| 95 | locale: string |
| 96 | children: ReactNode |
| 97 | }) { |
| 98 | return ( |
| 99 | <div |
| 100 | style={{ |
| 101 | display: "flex", |
| 102 | flexDirection: "column", |
| 103 | justifyContent: "center", |
| 104 | width: "100%", |
| 105 | height: "100%", |
| 106 | backgroundColor: "#111010", |
| 107 | padding: "0 80px", |
| 108 | fontFamily: "Hanken Grotesk", |
| 109 | }} |
| 110 | > |
| 111 | <div |
| 112 | style={{ |
| 113 | display: "flex", |
| 114 | flexDirection: "row", |
| 115 | alignItems: "center", |
| 116 | justifyContent: "space-between", |
| 117 | width: "100%", |
| 118 | }} |
| 119 | > |
| 120 | <div style={{ |
| 121 | {props.avatar ? |
| 122 | <img |
| 123 | src={props.avatar |
| 124 | width={88} |
| 125 | height={88} |
| 126 | style={{ borderRadius: |
| 127 | /> |
| 128 | ) : ( |
| 129 | <div |
| 130 | style={{ |
| 131 | display: "flex", |
| 132 | width: 88, |
| 133 | height: 88, |
| 134 | borderRadius: 12, |
| 135 | backgroundColor: "#27272a", |
| 136 | }} |
| 137 | /> |
| 138 | )} |
| 139 | <div |
| 140 | style={{ |
| 141 | display: "flex", |
| 142 | flexDirection: "column", |
| 143 | justifyContent: "center", |
| 144 | marginLeft: 20, |
| 145 | }} |
| 146 | > |
| 147 | <span style={{ |
| 148 | {OG_NAME} |
| 149 | </span> |
| 150 | <span style={{ |
| 151 | </div> |
| 152 | </div> |
| 153 | |
| 154 | <div |
| 155 | style={{ |
| 156 | display: "flex", |
| 157 | flexDirection: "row", |
| 158 | alignItems: "center", |
| 159 | color: "#9ca3af", |
| 160 | fontSize: 28, |
| 161 | }} |
| 162 | > |
| 163 | <span>{LOCALE_NAMES[props |
| 164 | <svg |
| 165 | width="24" |
| 166 | height="24" |
| 167 | viewBox="0 0 24 24" |
| 168 | fill="none" |
| 169 | stroke="#9ca3af" |
| 170 | strokeWidth="2" |
| 171 | strokeLinecap="round" |
| 172 | strokeLinejoin="round" |
| 173 | style={{ marginLeft: |
| 174 | > |
| 175 | <path d="M6 9l6 6 6-6 |
| 176 | </svg> |
| 177 | </div> |
| 178 | </div> |
| 179 | |
| 180 | {props.children} |
| 181 | </div> |
| 182 | ); |
| 183 | } |
| 184 | |
| 185 | export function OgBadge(props |
| 186 | return ( |
| 187 | <div |
| 188 | style={{ |
| 189 | display: "flex", |
| 190 | alignItems: "center", |
| 191 | border: "2px solid #262626", |
| 192 | backgroundColor: "#171717", |
| 193 | borderRadius: 6, |
| 194 | padding: "2px 10px", |
| 195 | color: "#f5f5f5", |
| 196 | }} |
| 197 | > |
| 198 | {props.children} |
| 199 | </div> |
| 200 | ); |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * The Next.js mark from icons/next.tsx, minus the `mask` and the two white |
| 205 | * gradients - Satori renders neither, so the app icon comes out blank here. |
| 206 | * Same geometry, solid white fills. |
| 207 | */ |
| 208 | export function NextMark(props |
| 209 | return ( |
| 210 | <svg viewBox="0 0 180 180 |
| 211 | <circle cx={90 |
| 212 | <path |
| 213 | d="M149.508 157.52L69.142 54H54V125.97H66.1136V69.3836L139.999 164.845C143.333 162.614 146.509 160.165 149.508 157.52Z" |
| 214 | fill="white" |
| 215 | /> |
| 216 | <rect x={115 |
| 217 | </svg> |
| 218 | ); |
| 219 | } |