Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement optimizations #75

Merged
merged 4 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: implement optimizations
  • Loading branch information
suyalcinkaya committed Mar 16, 2024
commit 1866b013b1c7d511ff49e8c4a41a1c2ac8b8dfa8
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
2 changes: 1 addition & 1 deletion src/app/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 2 additions & 4 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 @@ -20,13 +20,11 @@ async function fetchData(slug) {
const currentBookmark = bookmarks.find((bookmark) => bookmark.slug === slug)
if (!currentBookmark) notFound()

const bookmark = await getBookmark(currentBookmark._id)
if (!bookmark) notFound()
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
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
15 changes: 9 additions & 6 deletions src/app/writing/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('writing')) ?? {}
const [seoData = {}, mediumFontData, boldFontData] = await Promise.all([
getPageSeo('writing'),
getMediumFont(),
getBoldFont()
])
const { seo: { title, description, ogImageTitle, ogImageSubtitle } = {} } = seoData

return new ImageResponse(
(
Expand Down Expand Up @@ -47,13 +50,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
Loading