Skip to content

Commit

Permalink
feat: implement optimizations (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
suyalcinkaya committed Mar 16, 2024
1 parent c941edf commit 2129c6a
Show file tree
Hide file tree
Showing 26 changed files with 370 additions and 329 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"react-intersection-observer": "^9.5.2",
"react-tweet": "^3.2.0",
"react-wrap-balancer": "^1.1.0",
"server-only": "^0.0.1",
"sonner": "^1.4.3",
"sugar-high": "^0.6.0",
"tailwind-merge": "^2.2.1",
Expand Down
15 changes: 9 additions & 6 deletions src/app/[slug]/opengraph-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ImageResponse } from 'next/og'

import { OpenGraphImage } from '@/components/og-image'
import { getPageSeo } from '@/lib/contentful'
import { getMediumFont, getBoldFont } from '@/lib/utils'
import { getMediumFont, getBoldFont } from '@/lib/fonts'
import { sharedTitle, sharedImage } from '@/app/shared-metadata'

export const runtime = 'edge'
Expand All @@ -15,9 +15,12 @@ export const contentType = sharedImage.type

export default async function Image({ params }) {
const { slug } = params
const {
seo: { title, description, ogImageTitle, ogImageSubtitle }
} = (await getPageSeo(slug)) ?? {}
const [seoData = {}, mediumFontData, boldFontData] = await Promise.all([
getPageSeo(slug),
getMediumFont(),
getBoldFont()
])
const { seo: { title, description, ogImageTitle, ogImageSubtitle } = {} } = seoData

let icon = null
switch (slug) {
Expand Down Expand Up @@ -64,13 +67,13 @@ export default async function Image({ params }) {
fonts: [
{
name: 'SF Pro',
data: await getMediumFont(),
data: mediumFontData,
style: 'normal',
weight: 500
},
{
name: 'SF Pro',
data: await getBoldFont(),
data: boldFontData,
style: 'normal',
weight: 600
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function submitBookmark(formData) {
const cookieStore = cookies()

// Fake promise to simulate submitting the form
await new Promise((resolve) => setTimeout(resolve, 3000))
await new Promise((resolve) => setTimeout(resolve, 2000))

const formSubmissionCountCookie = cookieStore.get(BOOKMARK_SUBMISSION_COUNT_COOKIE_NAME)
if (formSubmissionCountCookie?.value >= MAX_BOOKMARK_SUBMISSIONS_PER_DAY) {
Expand All @@ -27,7 +27,7 @@ export async function submitBookmark(formData) {
},
body: JSON.stringify({
fields: {
URL: new URL(formData.url).origin,
URL: formData.url,
Email: formData.email,
Date: new Date().toISOString(),
Type: formData.type || 'Other'
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/revalidate/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { revalidatePath } from 'next/cache'
import { CONTENT_TYPES } from '@/lib/constants'

export const runtime = 'edge'
export const dynamic = 'auto'
export const dynamic = 'auto' // https://www.reddit.com/r/nextjs/comments/14iu6td/revalidatepath_not_updating_generatestaticparams/

const secret = `${process.env.NEXT_REVALIDATE_SECRET}`

Expand Down
8 changes: 4 additions & 4 deletions src/app/bookmarks/[slug]/opengraph-image.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ImageResponse } from 'next/og'

import { OpenGraphImage } from '@/components/og-image'
import { getMediumFont, getBoldFont } from '@/lib/utils'
import { getMediumFont, getBoldFont } from '@/lib/fonts'
import { getBookmarks } from '@/lib/raindrop'
import { sharedImage } from '@/app/shared-metadata'

Expand All @@ -15,7 +15,7 @@ export const contentType = sharedImage.type

export default async function Image({ params }) {
const { slug } = params
const bookmarks = await getBookmarks()
const [bookmarks, mediumFontData, boldFontData] = await Promise.all([getBookmarks(), getMediumFont(), getBoldFont()])
const currentBookmark = bookmarks.find((bookmark) => bookmark.slug === slug)
if (!currentBookmark) return null

Expand Down Expand Up @@ -47,13 +47,13 @@ export default async function Image({ params }) {
fonts: [
{
name: 'SF Pro',
data: await getMediumFont(),
data: mediumFontData,
style: 'normal',
weight: 500
},
{
name: 'SF Pro',
data: await getBoldFont(),
data: boldFontData,
style: 'normal',
weight: 600
}
Expand Down
8 changes: 3 additions & 5 deletions src/app/bookmarks/[slug]/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PageTitle } from '@/components/page-title'
import { FloatingHeader } from '@/components/floating-header'
import { LoadingSpinner } from '@/components/loading-spinner'
import { BookmarkList } from '@/components/bookmark-list.jsx'
import { getBookmark, getBookmarkItems, getBookmarks } from '@/lib/raindrop'
import { getBookmarkItems, getBookmarks } from '@/lib/raindrop'
import { sortByProperty } from '@/lib/utils'

export async function generateStaticParams() {
Expand All @@ -16,17 +16,15 @@ export async function generateStaticParams() {

async function fetchData(slug) {
const bookmarks = await getBookmarks()
const sortedBookmarks = sortByProperty(bookmarks, 'title')
const currentBookmark = bookmarks.find((bookmark) => bookmark.slug === slug)
if (!currentBookmark) notFound()

const bookmark = await getBookmark(currentBookmark._id)
if (!bookmark) notFound()
const sortedBookmarks = sortByProperty(bookmarks, 'title')
const bookmarkItems = await getBookmarkItems(currentBookmark._id)

return {
bookmarks: sortedBookmarks,
currentBookmark: bookmark.item,
currentBookmark,
bookmarkItems
}
}
Expand Down
15 changes: 9 additions & 6 deletions src/app/bookmarks/opengraph-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ImageResponse } from 'next/og'

import { OpenGraphImage } from '@/components/og-image'
import { getPageSeo } from '@/lib/contentful'
import { getMediumFont, getBoldFont } from '@/lib/utils'
import { getMediumFont, getBoldFont } from '@/lib/fonts'
import { sharedImage } from '@/app/shared-metadata'

export const runtime = 'edge'
Expand All @@ -14,9 +14,12 @@ export const size = {
export const contentType = sharedImage.type

export default async function Image() {
const {
seo: { title, description, ogImageTitle, ogImageSubtitle }
} = (await getPageSeo('bookmarks')) ?? {}
const [seoData = {}, mediumFontData, boldFontData] = await Promise.all([
getPageSeo('bookmarks'),
getMediumFont(),
getBoldFont()
])
const { seo: { title, description, ogImageTitle, ogImageSubtitle } = {} } = seoData

return new ImageResponse(
(
Expand Down Expand Up @@ -46,13 +49,13 @@ export default async function Image() {
fonts: [
{
name: 'SF Pro',
data: await getMediumFont(),
data: mediumFontData,
style: 'normal',
weight: 500
},
{
name: 'SF Pro',
data: await getBoldFont(),
data: boldFontData,
style: 'normal',
weight: 600
}
Expand Down
16 changes: 9 additions & 7 deletions src/app/journey/opengraph-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ImageResponse } from 'next/og'

import { OpenGraphImage } from '@/components/og-image'
import { getPageSeo } from '@/lib/contentful'
import { getMediumFont, getBoldFont } from '@/lib/utils'
import { getMediumFont, getBoldFont } from '@/lib/fonts'
import { sharedImage } from '@/app/shared-metadata'

export const runtime = 'edge'
Expand All @@ -14,10 +14,12 @@ export const size = {
export const contentType = sharedImage.type

export default async function Image() {
const seoData = (await getPageSeo('journey')) ?? {}
const {
seo: { title, description, ogImageTitle, ogImageSubtitle }
} = seoData
const [seoData = {}, mediumFontData, boldFontData] = await Promise.all([
getPageSeo('journey'),
getMediumFont(),
getBoldFont()
])
const { seo: { title, description, ogImageTitle, ogImageSubtitle } = {} } = seoData

return new ImageResponse(
(
Expand Down Expand Up @@ -47,13 +49,13 @@ export default async function Image() {
fonts: [
{
name: 'SF Pro',
data: await getMediumFont(),
data: mediumFontData,
style: 'normal',
weight: 500
},
{
name: 'SF Pro',
data: await getBoldFont(),
data: boldFontData,
style: 'normal',
weight: 600
}
Expand Down
8 changes: 5 additions & 3 deletions src/app/opengraph-image.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ImageResponse } from 'next/og'

import { OpenGraphImage } from '@/components/og-image'
import { getMediumFont, getBoldFont } from '@/lib/utils'
import { getMediumFont, getBoldFont } from '@/lib/fonts'
import { sharedTitle, sharedDescription, sharedImage } from '@/app/shared-metadata'

export const runtime = 'edge'
Expand All @@ -19,6 +19,8 @@ export const contentType = sharedImage.type
} */

export default async function Image() {
const [mediumFontData, boldFontData] = await Promise.all([getMediumFont(), getBoldFont()])

return new ImageResponse(
(
<OpenGraphImage
Expand Down Expand Up @@ -50,13 +52,13 @@ export default async function Image() {
fonts: [
{
name: 'SF Pro',
data: await getMediumFont(),
data: mediumFontData,
style: 'normal',
weight: 500
},
{
name: 'SF Pro',
data: await getBoldFont(),
data: boldFontData,
style: 'normal',
weight: 600
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import { getSortedPosts } from '@/lib/utils'

async function fetchData() {
const allPosts = await getAllPosts()
return { allPosts }
const sortedPosts = getSortedPosts(allPosts)
return { sortedPosts }
}

export default async function Home() {
const { allPosts } = await fetchData()
const sortedPosts = getSortedPosts(allPosts)
const { sortedPosts } = await fetchData()

return (
<ScrollArea className="flex flex-col" hasScrollTitle>
Expand Down
16 changes: 9 additions & 7 deletions src/app/workspace/opengraph-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ImageResponse } from 'next/og'

import { OpenGraphImage } from '@/components/og-image'
import { getPageSeo } from '@/lib/contentful'
import { getMediumFont, getBoldFont } from '@/lib/utils'
import { getMediumFont, getBoldFont } from '@/lib/fonts'
import { sharedImage } from '@/app/shared-metadata'

export const runtime = 'edge'
Expand All @@ -14,10 +14,12 @@ export const size = {
export const contentType = sharedImage.type

export default async function Image() {
const seoData = (await getPageSeo('workspace')) ?? {}
const {
seo: { title, description, ogImageTitle, ogImageSubtitle }
} = seoData
const [seoData = {}, mediumFontData, boldFontData] = await Promise.all([
getPageSeo('workspace'),
getMediumFont(),
getBoldFont()
])
const { seo: { title, description, ogImageTitle, ogImageSubtitle } = {} } = seoData

return new ImageResponse(
(
Expand Down Expand Up @@ -50,13 +52,13 @@ export default async function Image() {
fonts: [
{
name: 'SF Pro',
data: await getMediumFont(),
data: mediumFontData,
style: 'normal',
weight: 500
},
{
name: 'SF Pro',
data: await getBoldFont(),
data: boldFontData,
style: 'normal',
weight: 600
}
Expand Down
3 changes: 1 addition & 2 deletions src/app/workspace/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ export default async function Workspace() {
/>
<EmptyPlaceholder />
</div>

<div className="mt-2 overflow-hidden rounded-lg border md:mt-8">
<div className="mt-2 overflow-hidden rounded-lg border bg-white md:mt-8">
<Table>
<TableHeader>
<TableRow>
Expand Down
13 changes: 8 additions & 5 deletions src/app/writing/[slug]/opengraph-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ImageResponse } from 'next/og'

import { OpenGraphImage } from '@/components/og-image'
import { getWritingSeo } from '@/lib/contentful'
import { getMediumFont, getBoldFont } from '@/lib/utils'
import { getMediumFont, getBoldFont } from '@/lib/fonts'
import { sharedImage } from '@/app/shared-metadata'

export const runtime = 'edge'
Expand All @@ -15,9 +15,12 @@ export const contentType = sharedImage.type

export default async function Image({ params }) {
const { slug } = params
const seoData = await getWritingSeo(slug)
const [seoData, mediumFontData, boldFontData] = await Promise.all([
getWritingSeo(slug),
getMediumFont(),
getBoldFont()
])
if (!seoData) return null

const {
seo: { title, ogImageTitle, ogImageSubtitle }
} = seoData
Expand All @@ -35,13 +38,13 @@ export default async function Image({ params }) {
fonts: [
{
name: 'SF Pro',
data: await getMediumFont(),
data: mediumFontData,
style: 'normal',
weight: 500
},
{
name: 'SF Pro',
data: await getBoldFont(),
data: boldFontData,
style: 'normal',
weight: 600
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/writing/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { getSortedPosts } from '@/lib/utils'

async function fetchData() {
const allPosts = await getAllPosts()
return { allPosts }
const sortedPosts = getSortedPosts(allPosts)
return { sortedPosts }
}

export default async function WritingLayout({ children }) {
const { allPosts } = await fetchData()
const sortedPosts = getSortedPosts(allPosts)
const { sortedPosts } = await fetchData()

return (
<>
Expand Down
Loading

0 comments on commit 2129c6a

Please sign in to comment.