diff --git a/app/api/import/route.ts b/app/api/import/route.ts index 4a32bd5..6757332 100644 --- a/app/api/import/route.ts +++ b/app/api/import/route.ts @@ -6,7 +6,7 @@ import { STATUS_OK, STATUS_UNAUTHORIZED } from '@utils/statusCodes'; -import { singleNews, topNews } from '@utils/urls'; +import { getSingleNews, getTopNews } from '@utils/urls'; import { NewsDatabaseSchema, NewsDatabaseType } from '@utils/validationSchemas'; import { Resend } from 'resend'; @@ -18,7 +18,7 @@ export async function GET(request: Request) { } try { - const topStories: number[] = await fetch(topNews, { + const topStories: number[] = await fetch(getTopNews, { cache: 'no-store' }).then(res => res.json()); @@ -26,31 +26,33 @@ export async function GET(request: Request) { const newsPromises = topStories .slice(0, Number(process.env.NEWS_LIMIT)) - .map(id => fetch(singleNews(id)).then(res => res.json())); + .map(id => fetch(getSingleNews(id)).then(res => res.json())); const news: NewsDatabaseType[] = await Promise.all(newsPromises); - const upsertPromises = news.map(async singleNews => { - const validation = NewsDatabaseSchema.safeParse(singleNews); + const upsertPromises = news.map(async getSingleNews => { + const validation = NewsDatabaseSchema.safeParse(getSingleNews); if (validation.success) { console.info( - `Validated news N° ${singleNews.id} - ${singleNews.title}` + `Validated news N° ${getSingleNews.id} - ${getSingleNews.title}` ); const result = await prisma.news.upsert({ create: { ...validation.data, - id: singleNews.id + id: getSingleNews.id }, update: { ...validation.data }, where: { - id: singleNews.id + id: getSingleNews.id } }); - console.info(`Imported N° ${singleNews.id} - ${singleNews.title}`); + console.info( + `Imported N° ${getSingleNews.id} - ${getSingleNews.title}` + ); return result; } else { @@ -69,7 +71,7 @@ export async function GET(request: Request) { from: process.env.RESEND_FROM, to: [process.env.ADMIN_EMAIL], subject: 'Newsletter: import cron job', - text: `Found these ids ${topStories.join(', ')} and imported ${result.length} of them.` + text: `Imported ${result.length} news out of these ids: ${topStories.join(', ')}.` }); } diff --git a/app/api/mailing/route.ts b/app/api/mailing/route.ts index 872871e..eeb8c40 100644 --- a/app/api/mailing/route.ts +++ b/app/api/mailing/route.ts @@ -72,7 +72,7 @@ export async function GET(request: Request) { from: process.env.RESEND_FROM, to: [process.env.ADMIN_EMAIL], subject: 'Newsletter: mailing cron job', - text: `Found ${users.length} users and ${news.length} news to send.` + text: `Found ${users.length} users and ${news.length} news to send for ${new Date().toISOString()}.` }); } diff --git a/app/api/subscribe/route.ts b/app/api/subscribe/route.ts index 05102fe..a579289 100644 --- a/app/api/subscribe/route.ts +++ b/app/api/subscribe/route.ts @@ -13,8 +13,6 @@ import { ResponseType, SubscribeFormSchema } from '@utils/validationSchemas'; import * as crypto from 'crypto'; import { Resend } from 'resend'; -export const dynamic = 'force-dynamic'; // defaults to force-static - export async function POST(request: Request) { try { if (!process.env.RESEND_KEY || !process.env.RESEND_AUDIENCE) { diff --git a/app/layout.tsx b/app/layout.tsx index f4ac316..611d837 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,5 +1,5 @@ import Tiles from '@components/tiles/Tiles'; -import { cn } from '@utils/ui'; +import { cn } from '@utils/cn'; import { Analytics } from '@vercel/analytics/react'; import type { Metadata } from 'next'; import { Inter as FontSans } from 'next/font/google'; diff --git a/app/manifest.ts b/app/manifest.ts index ef2e90f..93e6ac9 100644 --- a/app/manifest.ts +++ b/app/manifest.ts @@ -4,7 +4,7 @@ export default function manifest(): MetadataRoute.Manifest { return { name: 'Newsletter', short_name: 'Newsletter', - description: 'Newsletter with Hackernews top stories', + description: 'Newsletter with top stories from the Hacker News forum', start_url: '/', display: 'standalone', background_color: '#fff', diff --git a/components/Button.tsx b/components/Button.tsx index ec89282..0e94c3b 100644 --- a/components/Button.tsx +++ b/components/Button.tsx @@ -1,5 +1,5 @@ import { Slot } from '@radix-ui/react-slot'; -import { cn } from '@utils/ui'; +import { cn } from '@utils/cn'; import * as React from 'react'; export type ButtonProps = { diff --git a/components/Card.tsx b/components/Card.tsx index a491ce4..d73a146 100644 --- a/components/Card.tsx +++ b/components/Card.tsx @@ -1,4 +1,4 @@ -import { cn } from '@utils/ui'; +import { cn } from '@utils/cn'; import * as React from 'react'; const Card = React.forwardRef< diff --git a/components/Input.tsx b/components/Input.tsx index fff1fec..63facad 100644 --- a/components/Input.tsx +++ b/components/Input.tsx @@ -1,4 +1,4 @@ -import { cn } from '@utils/ui'; +import { cn } from '@utils/cn'; import * as React from 'react'; const Input = React.forwardRef< diff --git a/components/Label.tsx b/components/Label.tsx index a2a07ab..6c46e09 100644 --- a/components/Label.tsx +++ b/components/Label.tsx @@ -1,7 +1,7 @@ 'use client'; import * as LabelPrimitive from '@radix-ui/react-label'; -import { cn } from '@utils/ui'; +import { cn } from '@utils/cn'; import { cva, type VariantProps } from 'class-variance-authority'; import * as React from 'react'; diff --git a/components/email/Newsletter.tsx b/components/email/Newsletter.tsx index 1358a81..731cad4 100644 --- a/components/email/Newsletter.tsx +++ b/components/email/Newsletter.tsx @@ -1,4 +1,4 @@ -import { sayings } from '@utils/sayings'; +import { getSayings } from '@utils/getSayings'; import { textTruncate } from '@utils/textTruncate'; import { NewsType } from '@utils/validationSchemas'; import Template from './Template'; @@ -9,7 +9,7 @@ export default function NewsletterTemplate(stories: NewsType[]) { template: (