Skip to content

Commit

Permalink
fix: don't throw on undefined video / image
Browse files Browse the repository at this point in the history
  • Loading branch information
v1rtl committed Jul 30, 2021
1 parent 87a446c commit a0ee8fe
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 102 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-ogp",
"version": "0.0.2",
"version": "0.0.3",
"description": "The ultimate React OpenGraph component",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -42,13 +42,13 @@
},
"homepage": "https://github.com/talentlessguy/react-ogp#readme",
"devDependencies": {
"@rollup/plugin-typescript": "^8.2.1",
"@types/react": "^17.0.4",
"@rollup/plugin-typescript": "^8.2.4",
"@types/react": "^17.0.15",
"react": "^17.0.2",
"rollup": "^2.46.0",
"rollup": "^2.55.1",
"rollup-plugin-terser": "^7.0.2",
"tslib": "^2.2.0",
"typescript": "^4.2.4"
"tslib": "^2.3.0",
"typescript": "^4.3.5"
},
"peerDependencies": {
"react": ">=16"
Expand Down
127 changes: 65 additions & 62 deletions pnpm-lock.yaml

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

70 changes: 36 additions & 34 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,42 +187,44 @@ export const OGP = ({
<meta name="profile:gender" content={profile.gender} />
</>
)}
{typeof video === 'string' ? (
<meta name="og:video" content={video} />
) : (
<>
<meta
property="og:video:secure_url"
content={video.url.includes('http://') ? video.url.replace('http://', 'https://') : video.url}
/>
<meta property="og:video:width" content={video.width.toString()} />
<meta property="og:video:height" content={video.height.toString()} />
<meta name="og:video:url" content={video.url} />
<meta property="og:video:type" content={video.type || 'video/mp4'} />
</>
)}
{video &&
(typeof video === 'string' ? (
<meta name="og:video" content={video} />
) : (
<>
<meta
property="og:video:secure_url"
content={video.url.includes('http://') ? video.url.replace('http://', 'https://') : video.url}
/>
<meta property="og:video:width" content={video.width.toString()} />
<meta property="og:video:height" content={video.height.toString()} />
<meta name="og:video:url" content={video.url} />
<meta property="og:video:type" content={video.type || 'video/mp4'} />
</>
))}
<meta name="og:locale" content={locale} />
<meta name="og:title" content={title} />
{typeof image === 'string' ? (
<>
<meta name="og:image" content={image} />
<meta
property="og:image:secure_url"
content={image.includes('http://') ? image.replace('http://', 'https://') : image}
/>
</>
) : (
<>
<meta
property="og:image:secure_url"
content={image.url.includes('http://') ? image.url.replace('http://', 'https://') : image.url}
/>
<meta property="og:image:width" content={image.width.toString()} />
<meta property="og:image:height" content={image.height.toString()} />
<meta name="og:image:url" content={image.url} />
<meta property="og:image:type" content={image.type || 'image/jpeg'} />
</>
)}
{image &&
(typeof image === 'string' ? (
<>
<meta name="og:image" content={image} />
<meta
property="og:image:secure_url"
content={image.includes('http://') ? image.replace('http://', 'https://') : image}
/>
</>
) : (
<>
<meta
property="og:image:secure_url"
content={image.url.includes('http://') ? image.url.replace('http://', 'https://') : image.url}
/>
<meta property="og:image:width" content={image.width.toString()} />
<meta property="og:image:height" content={image.height.toString()} />
<meta name="og:image:url" content={image.url} />
<meta property="og:image:type" content={image.type || 'image/jpeg'} />
</>
))}

<meta name="og:url" content={url} />
<meta property="og:site_name" content={siteName} />
Expand Down

0 comments on commit a0ee8fe

Please sign in to comment.