|
1 | 1 | import { html } from 'satori-html';
|
2 | 2 |
|
| 3 | +import { limitString } from '@/utils/strings'; |
| 4 | + |
3 | 5 | export interface TemplateProps {
|
4 | 6 | title: string;
|
5 | 7 | heroImageUrl: string;
|
6 | 8 | avatarImageUrl: string;
|
7 | 9 | siteUrl: string;
|
8 | 10 | }
|
9 | 11 |
|
10 |
| -const templateHtml = ({ title, heroImageUrl, avatarImageUrl, siteUrl }: TemplateProps) => html` |
11 |
| - <div class="flex p-8 h-full" style="background: linear-gradient(to right, #D1D5DB, #F3F4F6)"> |
12 |
| - <div class="flex w-full flex-row justify-between text-slate-900"> |
13 |
| - <!-- left column --> |
14 |
| - <div class="w-[550px] flex flex-col justify-between mr-6"> |
15 |
| - <!-- title --> |
16 |
| - <div class="flex text-6xl font-semibold mb-4">${title}</div> |
17 |
| -
|
18 |
| - <!-- avatar and site --> |
19 |
| - <div class="flex items-center"> |
20 |
| - <img |
21 |
| - src=${avatarImageUrl} |
22 |
| - alt="Nemanja Mitic" |
23 |
| - width="120" |
24 |
| - height="120" |
25 |
| - class="rounded-full mr-8" |
26 |
| - /> |
27 |
| - <div class="h-full flex items-center text-4xl break-words"> |
28 |
| - <div>${siteUrl}</div> |
| 12 | +const templateHtml = ({ title, heroImageUrl, avatarImageUrl, siteUrl }: TemplateProps) => { |
| 13 | + // 2 rows - max 30 chars |
| 14 | + // 1 row - max 18 chars |
| 15 | + const isLongSiteUrl = siteUrl.length > 17; |
| 16 | + |
| 17 | + // max 6 rows x 10-15 chars |
| 18 | + const limitedTitle = limitString(title, 70); |
| 19 | + |
| 20 | + return html` |
| 21 | + <div class="flex p-8 h-full" style="background: linear-gradient(to right, #D1D5DB, #F3F4F6)"> |
| 22 | + <div class="flex w-full flex-row justify-between text-slate-900"> |
| 23 | + <!-- left column --> |
| 24 | + <div class="w-[550px] flex flex-col justify-between mr-6"> |
| 25 | + <!-- title --> |
| 26 | + <div class="flex flex-grow text-6xl font-semibold mb-4">${limitedTitle}</div> |
| 27 | +
|
| 28 | + <!-- avatar and site --> |
| 29 | + <div class="flex items-center ${isLongSiteUrl ? 'flex-col justify-end items-start' : ''}"> |
| 30 | + <img |
| 31 | + src=${avatarImageUrl} |
| 32 | + alt="Nemanja Mitic" |
| 33 | + width="120" |
| 34 | + height="120" |
| 35 | + class="rounded-full mr-8" |
| 36 | + /> |
| 37 | + <div class="flex items-center ${isLongSiteUrl ? 'mt-4 text-3xl' : 'text-4xl'}"> |
| 38 | + <div>${siteUrl}</div> |
| 39 | + </div> |
29 | 40 | </div>
|
30 | 41 | </div>
|
31 |
| - </div> |
32 | 42 |
|
33 |
| - <!-- right column --> |
34 |
| - <div class="w-[550px] flex items-center"> |
35 |
| - <img src="${heroImageUrl}" class="h-full w-full rounded-md" style="object-fit: cover" /> |
| 43 | + <!-- right column --> |
| 44 | + <div class="w-[550px] flex items-center"> |
| 45 | + <img src="${heroImageUrl}" class="h-full w-full rounded-md" style="object-fit: cover" /> |
| 46 | + </div> |
36 | 47 | </div>
|
37 | 48 | </div>
|
38 |
| - </div> |
39 |
| -`; |
| 49 | + `; |
| 50 | +}; |
40 | 51 |
|
41 | 52 | export default templateHtml;
|
0 commit comments