-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathrenderEmail.tsx
31 lines (23 loc) · 994 Bytes
/
renderEmail.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { render } from '@react-email/render'
import Email from './email/Email'
import { filterItemsFromFeed } from './filterItems'
import { parseLastSuccess } from './parseLastSuccess'
import { parseFeeds, SettledFeed } from './parseFeeds'
import { getItemCount } from './getItemCount'
interface Props {
actionUrl: string
cache: SettledFeed[]
lastSuccess: string
pretty: boolean
}
const LIMIT_ITEMS_INITIAL_RUN = 3
export async function renderEmail({ actionUrl, cache, lastSuccess, pretty = false }: Partial<Props>) {
const { from, initialRun } = parseLastSuccess(lastSuccess)
const feeds = cache ?? (await parseFeeds())
const filteredFeeds = filterItemsFromFeed(feeds, from, initialRun ? LIMIT_ITEMS_INITIAL_RUN : undefined)
const itemCount = getItemCount(filteredFeeds)
const html = await render(<Email actionUrl={actionUrl} feeds={filteredFeeds} from={from} initialRun={initialRun} itemCount={itemCount} />, {
pretty,
})
return { html, itemCount, feeds }
}