Skip to content

Commit

Permalink
Merge pull request #175 from timlrx/update-newsletter
Browse files Browse the repository at this point in the history
Update newsletter APIs and contentlayer dependency
  • Loading branch information
timlrx authored Aug 11, 2024
2 parents b91eb82 + c4a356a commit b91991b
Show file tree
Hide file tree
Showing 11 changed files with 401 additions and 127 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-pandas-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'pliny': minor
---

remove revue from newsletter list
5 changes: 5 additions & 0 deletions .changeset/seven-parents-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'pliny': patch
---

update pliny to v0.5
5 changes: 5 additions & 0 deletions .changeset/stale-years-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'pliny': patch
---

update klaviyo api
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Pliny provides out of the box components to enhance your static site:
- Email Octopus
- Klaviyo
- Mailchimp
- Revue
- Command palette search with tailwind style sheet
- Algolia
- Kbar (local search)
Expand Down Expand Up @@ -245,7 +244,7 @@ import { NewsletterAPI } from 'pliny/newsletter'
import siteMetadata from '@/data/siteMetadata'

const handler = NewsletterAPI({
provider: '', // Use one of mailchimp, buttondown, convertkit, klaviyo, revue, emailOctopus
provider: '', // Use one of mailchimp, buttondown, convertkit, klaviyo emailOctopus
})

export { handler as GET, handler as POST }
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@
]
},
"packageManager": "[email protected]"
}
}
4 changes: 2 additions & 2 deletions packages/pliny/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
"@docsearch/react": "^3.5.0",
"@giscus/react": "^3.0.0",
"@mailchimp/mailchimp_marketing": "^3.0.80",
"contentlayer2": "^0.4.6",
"contentlayer2": "^0.5.0",
"copyfiles": "^2.4.1",
"github-slugger": "^2.0.0",
"js-yaml": "4.1.0",
"kbar": "0.1.0-beta.45",
"next-contentlayer2": "^0.4.6",
"next-contentlayer2": "^0.5.0",
"next-themes": "^0.3.0",
"probe-image-size": "^7.2.3",
"remark": "^15.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/pliny/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const sampleConfig: PlinyConfig = {
},
},
newsletter: {
// supports mailchimp, buttondown, convertkit, klaviyo, revue, emailOctopus
// supports mailchimp, buttondown, convertkit, klaviyo, emailOctopus
// Please add your .env file and modify it according to your selection
provider: 'buttondown',
},
Expand Down
9 changes: 1 addition & 8 deletions packages/pliny/src/newsletter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import { buttondownSubscribe } from './buttondown'
import { convertkitSubscribe } from './convertkit'
import { mailchimpSubscribe } from './mailchimp'
import { klaviyoSubscribe } from './klaviyo'
import { revueSubscribe } from './revue'
import { emailOctopusSubscribe } from './emailOctopus'

export interface NewsletterConfig {
provider: 'buttondown' | 'convertkit' | 'klaviyo' | 'mailchimp' | 'revue' | 'emailoctopus'
provider: 'buttondown' | 'convertkit' | 'klaviyo' | 'mailchimp' | 'emailoctopus'
}

export interface NewsletterRequest extends NextApiRequest {
Expand Down Expand Up @@ -42,9 +41,6 @@ async function NewsletterAPIHandler(
case 'klaviyo':
response = await klaviyoSubscribe(email)
break
case 'revue':
response = await revueSubscribe(email)
break
case 'emailoctopus':
response = await emailOctopusSubscribe(email)
break
Expand Down Expand Up @@ -80,9 +76,6 @@ async function NewsletterRouteHandler(req: NextRequest, options: NewsletterConfi
case 'klaviyo':
response = await klaviyoSubscribe(email)
break
case 'revue':
response = await revueSubscribe(email)
break
case 'emailoctopus':
response = await emailOctopusSubscribe(email)
break
Expand Down
59 changes: 45 additions & 14 deletions packages/pliny/src/newsletter/klaviyo.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,51 @@
export const klaviyoSubscribe = async (email: string) => {
const API_KEY = process.env.KLAVIYO_API_KEY
const LIST_ID = process.env.KLAVIYO_LIST_ID
const response = await fetch(
`https://a.klaviyo.com/api/v2/list/${LIST_ID}/subscribe?api_key=${API_KEY}`,
{
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',

const data = {
data: {
type: 'profile-subscription-bulk-create-job',
attributes: {
custom_source: 'Marketing Event',
profiles: {
data: [
{
type: 'profile',
attributes: {
email: email,
subscriptions: {
email: {
marketing: {
consent: 'SUBSCRIBED',
},
},
},
},
},
],
},
},
// You can add additional params here i.e. SMS, etc.
// https://developers.klaviyo.com/en/reference/subscribe
body: JSON.stringify({
profiles: [{ email: email }],
}),
}
)
relationships: {
list: {
data: {
type: 'list',
id: LIST_ID,
},
},
},
},
}

const response = await fetch('https://a.klaviyo.com/api/profile-subscription-bulk-create-jobs', {
method: 'POST',
headers: {
Authorization: `Klaviyo-API-Key ${API_KEY}`,
Accept: 'application/json',
'Content-Type': 'application/json',
revision: '2024-07-15',
},
body: JSON.stringify(data),
})

return response
}
15 changes: 0 additions & 15 deletions packages/pliny/src/newsletter/revue.ts

This file was deleted.

Loading

0 comments on commit b91991b

Please sign in to comment.