From 5407e2cf79299d1709c34fcd0f9cd2efc948efe2 Mon Sep 17 00:00:00 2001 From: Riccardo Date: Mon, 18 Dec 2023 18:17:50 +0100 Subject: [PATCH] style: general tweaking --- .env.example | 4 +- README.md | 6 + app/api/news/route.ts | 4 +- .../custom/background/tile/tileContent.tsx | 15 +-- components/emails/components/footer.tsx | 20 ++- components/emails/confirmation.tsx | 10 +- components/emails/newsletter.tsx | 114 +++++++----------- components/emails/template.tsx | 29 ++--- components/emails/unsubscribe.tsx | 4 +- utils/getRandomColor.ts | 8 ++ 10 files changed, 99 insertions(+), 115 deletions(-) create mode 100644 utils/getRandomColor.ts diff --git a/.env.example b/.env.example index ca96795..3b12db9 100644 --- a/.env.example +++ b/.env.example @@ -28,4 +28,6 @@ RESEND_KEY="" RESEND_FROM="" SECRET_HASH="" HOME_URL="" -MAINTENANCE_MODE=0 \ No newline at end of file +MAINTENANCE_MODE=0 +BRAND_NAME="" +BRAND_EMAIL="" \ No newline at end of file diff --git a/README.md b/README.md index 48a13b9..72706e5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # Hackernews newsletter +## Next up + +- Batch email (Resend: ETA early 2024) +- Custom url shortener for links in the newsletter +- Cron every 10 minutes: people are more likely to open the newsletter if delivered around the time when they subscribed (if cron becomes not enough, then the cost of sending all the emails might be a bigger issue) + ## Vercel basics Install vercel cli diff --git a/app/api/news/route.ts b/app/api/news/route.ts index 12cfff7..03a8e0d 100644 --- a/app/api/news/route.ts +++ b/app/api/news/route.ts @@ -6,10 +6,10 @@ export async function GET() { orderBy: { createdAt: 'desc' }, - take: 50 + take: 100 }); - if (news && news.length === 50) { + if (news && news.length === 100) { return ApiResponse(200, JSON.stringify(news)); } diff --git a/components/custom/background/tile/tileContent.tsx b/components/custom/background/tile/tileContent.tsx index f0c02d3..7df8f31 100644 --- a/components/custom/background/tile/tileContent.tsx +++ b/components/custom/background/tile/tileContent.tsx @@ -1,5 +1,6 @@ import { useState } from 'react'; import { z } from 'zod'; +import { getRandomColor } from '../../../../utils/getRandomColor'; import { NewsSchema } from '../../../../utils/schemas'; type CardContentProps = { @@ -7,15 +8,6 @@ type CardContentProps = { side: boolean; }; -function getRandomColor() { - const letters = '456789ABCDEF'; - let color = '#'; - for (let i = 0; i < 6; i++) { - color += letters[Math.floor(Math.random() * 12)]; - } - return color; -} - export function TileContent({ story, side }: CardContentProps) { const [firstColor, setFirstColor] = useState(getRandomColor()); const [secondColor, setSecondColor] = useState(getRandomColor()); @@ -32,14 +24,15 @@ export function TileContent({ story, side }: CardContentProps) { return (

{story.title}

-

{story.by}

+

by {story.by}

-
+ ); } diff --git a/components/emails/confirmation.tsx b/components/emails/confirmation.tsx index 803d670..44768fe 100644 --- a/components/emails/confirmation.tsx +++ b/components/emails/confirmation.tsx @@ -9,15 +9,13 @@ export default function ConfirmationTemplate(code: string) { -

- Dear subscriber, -

-

+

+

Dear subscriber,

+

thank you for subscribing to our newsletter! Please click the button below to confirm your subscription.

-
+
[] @@ -26,71 +23,52 @@ export default function NewsletterTemplate( return { subject: `What's new from Hackernews?`, template: ( - -
-
-
-

Good day!

-

- Here is something{' '} - {sayings[Math.floor(Math.random() * sayings.length)]}: -

-
- - - {stories.map(story => { - return ( -
-
-

- {story.title} -

-

{story.by}

-
- {story.text && ( -
-

500 - ? story.text.substring(0, 500) + '...' - : story.text - }} - /> -

- )} - {story.url && ( - - )} + +

+ Here is something{' '} + {sayings[Math.floor(Math.random() * sayings.length)]}: +

+ {stories.map(story => { + const background = getRandomColor(); + + return ( +
+
+

{story.title}

+

by {story.by}

+
+ {story.text && ( +
+

500 + ? story.text.substring(0, 500) + '...' + : story.text + }} + />

- ); - })} - - -
+ )} + {story.url && ( +
+ Read more +
+ )} +
+ ); + })}
-
- + } + /> ) }; } diff --git a/components/emails/template.tsx b/components/emails/template.tsx index d62308b..2b169e6 100644 --- a/components/emails/template.tsx +++ b/components/emails/template.tsx @@ -1,7 +1,6 @@ -import { Container } from '@react-email/container'; import { Html } from '@react-email/html'; import { Section } from '@react-email/section'; -import { Text } from '@react-email/text'; +import { getRandomColor } from '../../utils/getRandomColor'; import { Footer } from './components/footer'; type EmailProps = { @@ -10,26 +9,18 @@ type EmailProps = { }; export default function Email({ title, body }: EmailProps) { + const titleBackground = getRandomColor(); + return ( -
- +

-

{title}

- - {body} - -
+ {title} + +
{body}
diff --git a/components/emails/unsubscribe.tsx b/components/emails/unsubscribe.tsx index cc5c7c4..82b8194 100644 --- a/components/emails/unsubscribe.tsx +++ b/components/emails/unsubscribe.tsx @@ -9,8 +9,8 @@ export default function UnsubscribeTemplate() { -

+

+

You have been successfully unsubscribed from our newsletter. You won't receive any further communications from us unless you explicitly opt-in again. diff --git a/utils/getRandomColor.ts b/utils/getRandomColor.ts new file mode 100644 index 0000000..d91e981 --- /dev/null +++ b/utils/getRandomColor.ts @@ -0,0 +1,8 @@ +export function getRandomColor() { + const letters = '6789ABCDEF'; + let color = '#'; + for (let i = 0; i < 6; i++) { + color += letters[Math.floor(Math.random() * 10)]; + } + return color; +}