Skip to content

Commit 87e0323

Browse files
authored
Merge pull request #286 from iodigital-com/feature/og-image-api
feat(og): add new edge runtime function to generate updated OG image design
2 parents b57b3e8 + f19fd60 commit 87e0323

12 files changed

+8951
-33
lines changed

components/SEO.js

+6-32
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,31 @@ import Head from 'next/head'
22
import { useRouter } from 'next/router'
33
import removeMarkdown from 'markdown-to-text'
44
import siteMetadata from '@/data/siteMetadata'
5-
import { useBrandingTheme } from '@/lib/hooks/useBrandingTheme'
65

7-
const getConstructedDynamicOGImageURL = ({ title, featuredImages, authorList, date }) => {
8-
// eslint-disable-next-line react-hooks/rules-of-hooks
9-
let { theme } = useBrandingTheme()
6+
const getConstructedDynamicOGImageURL = ({ title, featuredImages, authorList }) => {
7+
const dynamicOgImageURL = new URL(`${siteMetadata.siteUrl}/api/og`)
108

11-
const dynamicOgImageURL = new URL('https://og-image-io.vercel.app/')
12-
const fileType = 'png'
139
const authorListFormatter = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' })
1410

15-
dynamicOgImageURL.pathname = `${encodeURIComponent(title)}.${fileType}`
16-
1711
const searchParams = [
1812
{
19-
key: 'teaserImage',
20-
value: featuredImages?.length && featuredImages[0].url,
13+
key: 'title',
14+
value: title?.replaceAll('_', ''),
2115
},
2216
{
2317
key: 'author',
2418
value: authorList?.length && authorListFormatter.format(authorList.map(({ name }) => name)),
2519
},
2620
{
27-
key: 'authorImage',
28-
value:
29-
authorList?.length &&
30-
authorList[0].avatar &&
31-
`https://techhub.iodigital.com${authorList[0].avatar}`,
32-
},
33-
{
34-
key: 'blendTheme',
35-
value: theme,
36-
},
37-
{
38-
key: 'date',
39-
value: date?.length && new Intl.DateTimeFormat('en').format(new Date(date)),
40-
},
41-
{
42-
key: 'domain',
43-
value: 'tech_hub',
21+
key: 'image',
22+
value: featuredImages?.[0]?.url,
4423
},
4524
]
4625

4726
searchParams.forEach(
4827
({ key, value }) => value && dynamicOgImageURL.searchParams.append(key, value)
4928
)
5029

51-
/*** added to prevent development generated image to be used for prod ***/
52-
if (process.env.NODE_ENV === 'development') {
53-
dynamicOgImageURL.searchParams.append('isDevelopment', 'true')
54-
}
55-
5630
return dynamicOgImageURL
5731
}
5832

package-lock.json

+178-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@supabase/supabase-js": "2.48.0",
2727
"@tailwindcss/forms": "0.5.10",
2828
"@tailwindcss/typography": "0.5.16",
29+
"@vercel/og": "^0.6.5",
2930
"autoprefixer": "10.4.20",
3031
"date-fns": "3.6.0",
3132
"github-slugger": "1.5.0",
@@ -69,6 +70,7 @@
6970
"cross-env": "7.0.3",
7071
"dedent": "0.7.0",
7172
"dotenv": "16.4.7",
73+
"esbuild": "^0.25.0",
7274
"eslint": "8.57.1",
7375
"eslint-config-next": "15.1.6",
7476
"eslint-config-prettier": "8.10.0",

0 commit comments

Comments
 (0)