Skip to content

Commit 2bc4727

Browse files
committed
✨ feat: Make email image optional
1 parent 076177d commit 2bc4727

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

emails/newsletter.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export interface NewsletterProps {
1919
subtitle: string
2020
summary: string
2121
postUrl: string
22-
imageUrl: string
23-
imageAlt: string
22+
imageUrl?: string
23+
imageAlt?: string
2424
}
2525

2626
Newsletter.PreviewProps = {
@@ -57,11 +57,13 @@ export default function Newsletter(props: Readonly<NewsletterProps>) {
5757
style={container}
5858
>
5959
<Section className="my-[16px]">
60-
<Img
61-
className="w-full rounded-xl object-cover"
62-
src={props.imageUrl}
63-
alt={props.imageAlt}
64-
/>
60+
{props.imageUrl && (
61+
<Img
62+
className="w-full rounded-xl object-cover"
63+
src={props.imageUrl}
64+
alt={props.imageAlt}
65+
/>
66+
)}
6567
<Section className="mt-[32px] text-center">
6668
<Text
6769
className="my-[16px] text-[18px] font-semibold leading-[28px]"

emails/sendEmail.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,18 @@ function getLatestPost(rootPath: string): NewsletterProps {
6868
content.indexOf("\n", content.indexOf("\n") + 1)
6969
)
7070

71-
return {
71+
const post: NewsletterProps = {
7272
title: data.title,
7373
subtitle: data.description,
7474
summary,
7575
postUrl: permalink.toString(),
76-
imageUrl: buildImageURL(slug, data.feature).toString(),
77-
imageAlt: data.featureAlt,
7876
}
77+
if (data.feature) {
78+
post.imageUrl = buildImageURL(slug, data.feature).toString()
79+
post.imageAlt = data.featureAlt
80+
}
81+
82+
return post
7983
}
8084

8185
function buildImageURL(postSlug: string, imageSlug: string): URL {

0 commit comments

Comments
 (0)