Skip to content

Commit 8e941c0

Browse files
John Richard Chipps-HardingPauloMFJ
andauthored
Share Image Size Meta (#22)
* Share Image Size Meta * Update README.md Co-authored-by: Paulo <[email protected]> * Update README.md Co-authored-by: Paulo <[email protected]> * Update src/components/MetaHeadEmbed.tsx Co-authored-by: Paulo <[email protected]> * Linting Co-authored-by: Paulo <[email protected]>
1 parent 0bd2478 commit 8e941c0

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export default PageLayout;
7474
| **keywords** | string&#124;string[] | **No** | List of SEO keywords describing what your webpage does. Example, `"your, tags"` or `["your", "tags"]`. |
7575
| **imageUrl** | string | **Yes** | Image url of asset to share. Recommended aspect ratio for landscape is 1.9:1 (1200x630) or for squares 1:1 (1200x1200). For more info, visit [here](https://iamturns.com/open-graph-image-size/). If a relative URL is provided, `baseSiteUrl` is prefixed. If specifying a relative URL do not add the leading slash. |
7676
| **imageAlt** | string | **Yes** | Image alt for users who are visually impaired. |
77+
| **imageWidth** | number | **No** | Width of share image, defaults to `1200`. |
78+
| **imageHeight** | number | **No** | Height of share image, defaults to `630`. |
7779
| **locale** | string | **No** | The locale these tags are marked up in, such as; `en_GB`, `fr_FR` and `es_ES`. Defaults to `en_US`. |
7880
| **twitter** | TwitterEmbedProps | **No** | Optional twitter embed properties to include. |
7981

src/components/MetaHeadEmbed.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,17 @@ export interface MetaEmbedProps {
8585
* Image url of asset to share. Recommended aspect ratio for landscape is
8686
* 1.9:1 (1200x630) or for squares 1:1 (1200x1200).
8787
*/
88-
imageUrl: string;
88+
imageUrl?: string;
89+
90+
/**
91+
* Width of share image.
92+
*/
93+
imageWidth?: number;
94+
95+
/**
96+
* height of share image.
97+
*/
98+
imageHeight?: number;
8999

90100
/** Image alt for users who are visually impaired. */
91101
imageAlt: string;
@@ -114,6 +124,8 @@ const MetaHeadEmbed = ({
114124
keywords,
115125
imageUrl,
116126
imageAlt,
127+
imageWidth = 1200,
128+
imageHeight = 630,
117129
locale = "en_US",
118130
twitter,
119131
}: MetaEmbedProps) => {
@@ -157,6 +169,16 @@ const MetaHeadEmbed = ({
157169
content={description}
158170
/>,
159171
<meta key="og:image" property="og:image" content={image} />,
172+
<meta
173+
key="og:image:width"
174+
property="og:image:width"
175+
content={imageWidth.toString()}
176+
/>,
177+
<meta
178+
key="og:image:height"
179+
property="og:image:height"
180+
content={imageHeight.toString()}
181+
/>,
160182
<meta key="og:image:alt" property="og:image:alt" content={imageAlt} />,
161183
<meta key="og:site_name" property="og:site_name" content={siteTitle} />,
162184
<meta key="og:locale" property="og:locale" content={locale} />,

0 commit comments

Comments
 (0)