Skip to content

Commit 3ae60b4

Browse files
authored
Merge pull request #7595 from schrodingersket/bugfix/7503
#7503: `ogImage` and `ogUrl` are now both processed server-side before being passed to the client in publicly shared paths.
2 parents 946aabc + ba99682 commit 3ae60b4

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/packages/next/components/path/path.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export interface PublicPathProps {
7474
created: string|null; // ISO 8601 string
7575
last_edited: string|null; // ISO 8601 string
7676
ogUrl?: string; // Open Graph URL for social media sharing
77+
ogImage?: string; // Open Graph image for social media sharing
7778
}
7879

7980
export default function PublicPath({

src/packages/next/pages/share/public_paths/[...id].tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,18 @@ export default (props: PublicPathProps) => (
1919
<>
2020
<PublicPath {...props} />
2121
<NextHead>
22-
<meta property="og:type" content="article" />
22+
<meta property="og:type" content="article"/>
23+
<meta property="og:title" content={props.path}/>
2324

24-
<meta property="og:title" content={props.path} />
25-
<meta property="og:description" content={props.description} />
26-
<meta property="og:url" content={props.ogUrl} />
27-
{props.customize && (
28-
<meta
29-
property="og:image"
30-
content={
31-
props.customize.logoSquareURL ||
32-
`${props.customize.siteURL}${ogShareLogo.src}`
33-
}
34-
/>
25+
{props.description && (
26+
<meta property="og:description" content={props.description}/>
27+
)}
28+
{props.ogUrl && (
29+
<meta property="og:url" content={props.ogUrl}/>
30+
)}
31+
{props.ogImage && (
32+
<meta property="og:image" content={props.ogImage}/>
3533
)}
36-
3734
{props.created && (
3835
<meta property="article:published_time" content={props.created}/>
3936
)}
@@ -74,13 +71,18 @@ export async function getServerSideProps(context) {
7471

7572
const customize = await withCustomize({ context, props });
7673

77-
if (customize != null) {
74+
if (customize?.props?.customize != null) {
7875
// Add full URL for social media sharing
7976
//
8077
customize.props.ogUrl = `${customize.props.customize.siteURL}${shareURL(
8178
id,
8279
relativePath,
8380
)}`;
81+
82+
// Add image path for social media sharing
83+
//
84+
customize.props.ogImage = customize.props.customize.logoSquareURL ||
85+
`${customize.props.customize.siteURL}${ogShareLogo.src}`;
8486
}
8587

8688
return customize;

0 commit comments

Comments
 (0)