Skip to content

Commit

Permalink
Merge pull request #177 from lappemic/add-beehiiv
Browse files Browse the repository at this point in the history
Add beehiiv as newsletter platform
  • Loading branch information
timlrx authored Aug 16, 2024
2 parents 7837e5c + 3b4fe2b commit c898200
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .changeset/chilly-ladybugs-call.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions packages/pliny/src/newsletter/beehiiv.ts
Original file line number Diff line number Diff line change
@@ -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
}
9 changes: 8 additions & 1 deletion packages/pliny/src/newsletter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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` })
}
Expand Down Expand Up @@ -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 })
}
Expand Down

0 comments on commit c898200

Please sign in to comment.