Skip to content

Commit

Permalink
⚡️ Lighten bundle size
Browse files Browse the repository at this point in the history
  • Loading branch information
gianmarco.bado committed Apr 10, 2024
1 parent 3c92430 commit 246d4ff
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 68 deletions.
40 changes: 0 additions & 40 deletions lib/ClubMember.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { fakerIT as faker } from '@faker-js/faker'
import { match } from 'ts-pattern'

import type { PageObjectResponse } from '@notionhq/client/build/src/api-endpoints'
Expand Down Expand Up @@ -312,45 +311,6 @@ const propertyMatcher = <TOutput extends string | boolean | Date | undefined>(
)
.otherwise(() => undefined) as any // HACK type

export const mockMemberGenerator = function* () {
for (const payment of Object.values(PAYMENT_STATUS)) {
for (const membership of Object.values(MEMBERSHIP_STATUS)) {
for (const memberType of Object.values(MEMBERSHIP_TYPE)) {
const firstName = faker.person.firstName()
const lastName = faker.person.lastName()
const email = faker.internet
.email({
firstName,
lastName,
provider: 'fakemail.dev'
})
.toLowerCase()

yield new ClubMember(
firstName,
lastName,
payment,
faker.location.zipCode(),
'XXXXXX00X00X000X',
true,
true,
new Date(),
faker.date.birthdate(),
email,
faker.location.streetAddress(),
faker.location.city(),
faker.location.state({ abbreviated: true }),
faker.location.state({ abbreviated: true }),
faker.location.city(),
membership,
faker.phone.number(),
memberType
)
}
}
}
}

export const TEST_MEMBER = new ClubMember(
'Mariolone',
'Bubbarello',
Expand Down
47 changes: 47 additions & 0 deletions lib/mocks/ClubMember.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { fakerIT as faker } from '@faker-js/faker'

import { ClubMember } from '../ClubMember'
import {
PAYMENT_STATUS,
MEMBERSHIP_STATUS,
MEMBERSHIP_TYPE
} from '../constants'

export const mockMemberGenerator = function* () {
for (const payment of Object.values(PAYMENT_STATUS)) {
for (const membership of Object.values(MEMBERSHIP_STATUS)) {
for (const memberType of Object.values(MEMBERSHIP_TYPE)) {
const firstName = faker.person.firstName()
const lastName = faker.person.lastName()
const email = faker.internet
.email({
firstName,
lastName,
provider: 'fakemail.dev'
})
.toLowerCase()

yield new ClubMember(
firstName,
lastName,
payment,
faker.location.zipCode(),
'XXXXXX00X00X000X',
true,
true,
new Date(),
faker.date.birthdate(),
email,
faker.location.streetAddress(),
faker.location.city(),
faker.location.state({ abbreviated: true }),
faker.location.state({ abbreviated: true }),
faker.location.city(),
membership,
faker.phone.number(),
memberType
)
}
}
}
}
3 changes: 2 additions & 1 deletion pages/api/create-mock-entries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Effect, Stream, pipe, Exit, Cause } from 'effect'
import ProgressBar from 'progress'
import chalk from 'chalk'

import { ClubMember, mockMemberGenerator } from '@/lib/ClubMember'
import { ClubMember } from '@/lib/ClubMember'
import { mockMemberGenerator } from '@/lib/mocks/ClubMember'
import { createRegisterOfMemberEntry } from '@/lib/notion'
import { failWrapper } from '@/lib/utils'

Expand Down
54 changes: 27 additions & 27 deletions pages/api/social-image.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import * as React from 'react'
import { NextRequest } from 'next/server'
import { ImageResponse } from '@vercel/og'
import type { NextRequest } from 'next/server'

import { api, apiHost, rootNotionPageId } from '@/lib/config'
import { NotionPageInfo } from '@/lib/types'
import type { NotionPageInfo } from '@/lib/types'

// You can use another font if you subscribe to vercel Pro plan with code size limit of 2MB
// const interRegularFontP = fetch(
// new URL('../../public/fonts/Inter-Regular.ttf', import.meta.url)
// ).then((res) => res.arrayBuffer())

const interBoldFontP = fetch(
new URL('../../public/fonts/Inter-SemiBold.ttf', import.meta.url)
).then((res) => res.arrayBuffer())
// 10/04/2024(jammy): Vercel decided that this function is too heavy *again* for
// their Edge runtime, so I'm trying to reduce the bundle size as much as I can

// const interBoldFontP = fetch(
// new URL('../../public/fonts/Inter-SemiBold.ttf', import.meta.url)
// ).then((res) => res.arrayBuffer())

export const config = {
runtime: 'experimental-edge'
Expand All @@ -38,13 +41,10 @@ export default async function OGImage(req: NextRequest) {
const pageInfo: NotionPageInfo = await pageInfoRes.json()
console.log(pageInfo)

const [
// interRegularFont,
interBoldFont
] = await Promise.all([
// interRegularFontP,
interBoldFontP
])
// const [interRegularFont, interBoldFont] = await Promise.all([
// interRegularFontP,
// interBoldFontP
// ])

return new ImageResponse(
(
Expand Down Expand Up @@ -168,21 +168,21 @@ export default async function OGImage(req: NextRequest) {
),
{
width: 1200,
height: 630,
fonts: [
// {
// name: 'Inter',
// data: interRegularFont,
// style: 'normal',
// weight: 400
// },
{
name: 'Inter',
data: interBoldFont,
style: 'normal',
weight: 700
}
]
height: 630
// fonts: [
// {
// name: 'Inter',
// data: interRegularFont,
// style: 'normal',
// weight: 400
// },
// {
// name: 'Inter',
// data: interBoldFont,
// style: 'normal',
// weight: 700
// }
// ]
}
)
}

0 comments on commit 246d4ff

Please sign in to comment.