-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(articles): open graph image template + editor with preview * Merge branch 'main' into vh/feat/articles/social-image-editor-with-pr…
- Loading branch information
1 parent
1efc391
commit a6f19e2
Showing
8 changed files
with
156 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
apps/course-builder-web/src/app/[article]/opengraph-image.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { ImageResponse } from 'next/og' | ||
import { getArticle } from '@/lib/articles' | ||
|
||
export const runtime = 'edge' | ||
export const revalidate = 60 | ||
|
||
export default async function ArticleOG({ params }: { params: { article: string } }) { | ||
// const authorPhoto = fetch( | ||
// new URL(`../../public/images/author.jpg`, import.meta.url) | ||
// ).then(res => res.arrayBuffer()); | ||
|
||
// fonts | ||
const inter500 = fetch( | ||
new URL(`../../../node_modules/@fontsource/inter/files/inter-latin-500-normal.woff`, import.meta.url), | ||
).then((res) => res.arrayBuffer()) | ||
|
||
const resource = await getArticle(params.article) | ||
|
||
return new ImageResponse( | ||
( | ||
<div tw="flex p-10 h-full w-full bg-white flex-col" style={font('Inter 500')}> | ||
<main tw="flex flex-col gap-5 h-full flex-grow items-center justify-center"> | ||
<div tw="absolute text-[32px] top-5">Course Builder</div> | ||
<div tw="text-[48px]">{resource?.title}</div> | ||
{/* eslint-disable-next-line @next/next/no-img-element */} | ||
{/* <img | ||
tw="rounded-full h-74" | ||
alt={author.name} | ||
@ts-ignore | ||
src={await authorPhoto} | ||
/> */} | ||
</main> | ||
<Background /> | ||
</div> | ||
), | ||
{ | ||
width: 1200, | ||
height: 630, | ||
fonts: [ | ||
{ | ||
name: 'Inter 500', | ||
data: await inter500, | ||
}, | ||
], | ||
}, | ||
) | ||
} | ||
|
||
// lil helper for more succinct styles | ||
function font(fontFamily: string) { | ||
return { fontFamily } | ||
} | ||
|
||
const Background = () => { | ||
return ( | ||
<svg | ||
style={{ position: 'absolute', opacity: 0.05 }} | ||
width="1200" | ||
height="630" | ||
viewBox="0 0 1200 630" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<g clip-path="url(#clip0_50_18106)"> | ||
<line y1="125.5" x2="1200" y2="125.5" stroke="black" /> | ||
<line y1="251.5" x2="1200" y2="251.5" stroke="black" /> | ||
<line y1="377.5" x2="1200" y2="377.5" stroke="black" /> | ||
<line y1="503.5" x2="1200" y2="503.5" stroke="black" /> | ||
<line x1="150.5" y1="-2.18557e-08" x2="150.5" y2="630" stroke="black" /> | ||
<line x1="300.5" y1="-2.18557e-08" x2="300.5" y2="630" stroke="black" /> | ||
<line x1="450.5" y1="-2.18557e-08" x2="450.5" y2="630" stroke="black" /> | ||
<line x1="600.5" y1="-2.18557e-08" x2="600.5" y2="630" stroke="black" /> | ||
<line x1="750.5" y1="-2.18557e-08" x2="750.5" y2="630" stroke="black" /> | ||
<line x1="900.5" y1="-2.18557e-08" x2="900.5" y2="630" stroke="black" /> | ||
<line x1="1050.5" y1="-2.18557e-08" x2="1050.5" y2="630" stroke="black" /> | ||
</g> | ||
<defs> | ||
<clipPath id="clip0_50_18106"> | ||
<rect width="1200" height="630" fill="white" /> | ||
</clipPath> | ||
</defs> | ||
</svg> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.