11import { useEffect } from "preact/hooks" ;
22
3- export function Head ( { title, description, image } ) {
3+ export function Head ( { title, description, image, siteName , url } ) {
44 useEffect ( ( ) => {
55 if ( title ) {
66 document . title = title ;
@@ -14,6 +14,26 @@ export function Head({ title, description, image }) {
1414 }
1515 metaDesc . setAttribute ( "content" , description ) ;
1616 }
17+ if ( siteName ) {
18+ let metaSiteName = document . querySelector (
19+ 'meta[property="og:site_name"]' ,
20+ ) ;
21+ if ( ! metaSiteName ) {
22+ metaSiteName = document . createElement ( "meta" ) ;
23+ metaSiteName . setAttribute ( "property" , "og:site_name" ) ;
24+ document . head . appendChild ( metaSiteName ) ;
25+ }
26+ metaSiteName . setAttribute ( "content" , siteName ) ;
27+ }
28+ if ( url ) {
29+ let metaOgUrl = document . querySelector ( 'meta[property="og:url"]' ) ;
30+ if ( ! metaOgUrl ) {
31+ metaOgUrl = document . createElement ( "meta" ) ;
32+ metaOgUrl . setAttribute ( "property" , "og:url" ) ;
33+ document . head . appendChild ( metaOgUrl ) ;
34+ }
35+ metaOgUrl . setAttribute ( "content" , url ) ;
36+ }
1737 if ( image ) {
1838 let metaOgImg = document . querySelector ( 'meta[property="og:image"]' ) ;
1939 if ( ! metaOgImg ) {
@@ -22,8 +42,16 @@ export function Head({ title, description, image }) {
2242 document . head . appendChild ( metaOgImg ) ;
2343 }
2444 metaOgImg . setAttribute ( "content" , image ) ;
45+
46+ let metaTwImg = document . querySelector ( 'meta[name="twitter:image"]' ) ;
47+ if ( ! metaTwImg ) {
48+ metaTwImg = document . createElement ( "meta" ) ;
49+ metaTwImg . setAttribute ( "name" , "twitter:image" ) ;
50+ document . head . appendChild ( metaTwImg ) ;
51+ }
52+ metaTwImg . setAttribute ( "content" , image ) ;
2553 }
26- } , [ title , description , image ] ) ;
54+ } , [ title , description , image , siteName , url ] ) ;
2755
2856 return null ;
2957}
0 commit comments