Skip to content

Commit

Permalink
feat: preview meta image OG Protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
aacmal committed Jun 29, 2023
1 parent 0f899c3 commit 8ba8aaf
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"@ducanh2912/next-pwa": "^9.0.1",
"@vercel/og": "^0.5.8",
"classnames": "^2.3.2",
"framer-motion": "^10.12.10",
"next": "13.4.4",
Expand Down
126 changes: 125 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 107 additions & 0 deletions src/app/api/og/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { getChapter } from '@utils/chapter';
import { ImageResponse } from '@vercel/og';
import { NextRequest } from 'next/server';

export const runtime = 'edge';

export async function GET(req: NextRequest) {
try {
const { searchParams } = new URL(req.url);
const hasChapterId = searchParams.has('chapterId');

if (!hasChapterId) {
return new ImageResponse(
(
<div
style={{
width: '100%',
height: '100%',
backgroundColor: '#fff',
color: '#000',
}}
>
Missing chapterId
</div>
)
);
}

const chapterData = await getChapter(
parseInt(searchParams.get('chapterId'))
);

return new ImageResponse(
(
<div
style={{
display: 'flex',
height: '100%',
width: '100%',
alignItems: 'center',
justifyContent: 'center',
letterSpacing: '-.02em',
fontWeight: 700,
background: 'white',
}}
>
<div
style={{
left: 42,
top: 42,
position: 'absolute',
display: 'flex',
alignItems: 'center',
}}
>
<span
style={{
width: 24,
height: 24,
background: '#10b981',
borderRadius: '100%',
}}
/>
<span
style={{
marginLeft: 8,
fontSize: 20,
color: '#10b981',
}}
>
quran.acmal.me
</span>
</div>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
padding: '20px 20px',
fontSize: 32,
width: '100%',
maxWidth: 750,
textAlign: 'center',
backgroundColor: '#10b981',
color: 'white',
lineHeight: 1.4,
borderRadius: '15px',
flexWrap: 'nowrap',
}}
>
<div
style={{
whiteSpace: 'nowrap',
}}
>
{chapterData.name_complex}
</div>
<div>{chapterData.name_arabic}</div>
</div>
</div>
)
);
} catch (error) {
console.error(error);
return new Response('Error', { status: 500 });
}
}

1 comment on commit 8ba8aaf

@vercel
Copy link

@vercel vercel bot commented on 8ba8aaf Jun 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

pustaka-islam – ./

pustaka-islam-git-master-axcamz.vercel.app
pustakaislam.vercel.app
pustaka-islam-axcamz.vercel.app

Please sign in to comment.