diff --git a/.changeset/chilly-ladybugs-call.md b/.changeset/chilly-ladybugs-call.md new file mode 100644 index 0000000..9b8381a --- /dev/null +++ b/.changeset/chilly-ladybugs-call.md @@ -0,0 +1,8 @@ +--- +'pliny': patch +--- + +Added Beehiiv newsletter integration + +- Created new beehiiv.ts file with subscription functionality +- Updated index.ts to include Beehiiv as a newsletter provider option diff --git a/README.md b/README.md index 48ae9c1..5b0fa86 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ Pliny provides out of the box components to enhance your static site: - Email Octopus - Klaviyo - Mailchimp + - Beehiiv - Command palette search with tailwind style sheet - Algolia - Kbar (local search) diff --git a/packages/pliny/src/newsletter/beehiiv.ts b/packages/pliny/src/newsletter/beehiiv.ts new file mode 100644 index 0000000..2e56081 --- /dev/null +++ b/packages/pliny/src/newsletter/beehiiv.ts @@ -0,0 +1,23 @@ +export const beehiivSubscribe = async (email: string) => { + const API_KEY = process.env.BEEHIIV_API_KEY + const PUBLICATION_ID = process.env.BEEHIIV_PUBLICATION_ID + const API_URL = 'https://api.beehiiv.com/v2' + + const data = { + email, + publication_id: PUBLICATION_ID, + reactivate_existing: false, + send_welcome_email: true, + } + + const response = await fetch(`${API_URL}/subscribers`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${API_KEY}`, + }, + body: JSON.stringify(data), + }) + + return response +} \ No newline at end of file diff --git a/packages/pliny/src/newsletter/index.ts b/packages/pliny/src/newsletter/index.ts index c4a96ad..9a8ba67 100644 --- a/packages/pliny/src/newsletter/index.ts +++ b/packages/pliny/src/newsletter/index.ts @@ -6,9 +6,10 @@ import { convertkitSubscribe } from './convertkit' import { mailchimpSubscribe } from './mailchimp' import { klaviyoSubscribe } from './klaviyo' import { emailOctopusSubscribe } from './emailOctopus' +import { beehiivSubscribe } from './beehiiv' export interface NewsletterConfig { - provider: 'buttondown' | 'convertkit' | 'klaviyo' | 'mailchimp' | 'emailoctopus' + provider: 'buttondown' | 'convertkit' | 'klaviyo' | 'mailchimp' | 'emailoctopus' | 'beehiiv' } export interface NewsletterRequest extends NextApiRequest { @@ -44,6 +45,9 @@ async function NewsletterAPIHandler( case 'emailoctopus': response = await emailOctopusSubscribe(email) break + case 'beehiiv': + response = await beehiivSubscribe(email) + break default: res.status(500).json({ error: `${options.provider} not supported` }) } @@ -79,6 +83,9 @@ async function NewsletterRouteHandler(req: NextRequest, options: NewsletterConfi case 'emailoctopus': response = await emailOctopusSubscribe(email) break + case 'beehiiv': + response = await beehiivSubscribe(email) + break default: return NextResponse.json({ error: `${options.provider} not supported` }, { status: 500 }) }