@@ -2,57 +2,31 @@ import Head from 'next/head'
2
2
import { useRouter } from 'next/router'
3
3
import removeMarkdown from 'markdown-to-text'
4
4
import siteMetadata from '@/data/siteMetadata'
5
- import { useBrandingTheme } from '@/lib/hooks/useBrandingTheme'
6
5
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` )
10
8
11
- const dynamicOgImageURL = new URL ( 'https://og-image-io.vercel.app/' )
12
- const fileType = 'png'
13
9
const authorListFormatter = new Intl . ListFormat ( 'en' , { style : 'long' , type : 'conjunction' } )
14
10
15
- dynamicOgImageURL . pathname = `${ encodeURIComponent ( title ) } .${ fileType } `
16
-
17
11
const searchParams = [
18
12
{
19
- key : 'teaserImage ' ,
20
- value : featuredImages ?. length && featuredImages [ 0 ] . url ,
13
+ key : 'title ' ,
14
+ value : title ?. replaceAll ( '_' , '' ) ,
21
15
} ,
22
16
{
23
17
key : 'author' ,
24
18
value : authorList ?. length && authorListFormatter . format ( authorList . map ( ( { name } ) => name ) ) ,
25
19
} ,
26
20
{
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 ,
44
23
} ,
45
24
]
46
25
47
26
searchParams . forEach (
48
27
( { key, value } ) => value && dynamicOgImageURL . searchParams . append ( key , value )
49
28
)
50
29
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
-
56
30
return dynamicOgImageURL
57
31
}
58
32
0 commit comments