Skip to content

Commit

Permalink
feat: optimize og image generation
Browse files Browse the repository at this point in the history
  • Loading branch information
BrickheadJohnny committed Jan 28, 2025
1 parent 9f2f9c9 commit de251c6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
10 changes: 9 additions & 1 deletion src/components/common/LinkPreviewHead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ type Props = {
path: string
}

const getTimestamp = () => {
const rounded = new Date()
rounded.setMinutes(0)
rounded.setSeconds(0)
rounded.setMilliseconds(0)
return rounded.getTime()
}

const LinkPreviewHead = ({ path }: Props) => {
const url = `https://guild.xyz/api/linkpreview/${Date.now()?.toString()}/${path}`
const url = `https://guild.xyz/api/linkpreview/${getTimestamp()}/${path}`

return (
<Head>
Expand Down
7 changes: 3 additions & 4 deletions src/pages/api/linkpreview/[timestamp]/[guild]/[group].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import loadGoogleFont from "fonts/loadGoogleFont"
import { ImageResponse } from "next/og"
import { Guild } from "types"

export const config = {
runtime: "edge",
}

const interFont = loadGoogleFont("Inter", "400")
const interBoldFont = loadGoogleFont("Inter", "700")
const dystopianFont = fetch(
Expand Down Expand Up @@ -260,6 +256,9 @@ const handler = async (req, _) => {
</div>
</div>,
{
headers: {
"Cache-Control": "s-maxage=3600", // 1 hour
},
width: 800,
height: 450,
fonts: [
Expand Down
7 changes: 3 additions & 4 deletions src/pages/api/linkpreview/[timestamp]/[guild]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import loadGoogleFont from "fonts/loadGoogleFont"
import { ImageResponse } from "next/og"
import { Guild } from "types"

export const config = {
runtime: "edge",
}

const interFont = loadGoogleFont("Inter", "400")
const interBoldFont = loadGoogleFont("Inter", "700")
const dystopianFont = fetch(
Expand Down Expand Up @@ -246,6 +242,9 @@ const handler = async (req, _) => {
</div>
</div>,
{
headers: {
"Cache-Control": "s-maxage=3600", // 1 hour
},
width: 800,
height: 450,
fonts: [
Expand Down

0 comments on commit de251c6

Please sign in to comment.