Skip to content

Commit 8c82ad8

Browse files
authored
Merge pull request #1369 from prezly/fix/dev-21884-social-sharing-message
[DEV-21884] Fix - Story custom social sharing text
2 parents ed2ee2b + 124e87e commit 8c82ad8

File tree

4 files changed

+33
-38
lines changed

4 files changed

+33
-38
lines changed

src/components/SocialShare/SocialShare.tsx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import { analytics } from '@/utils';
2424
import styles from './SocialShare.module.scss';
2525

2626
interface Props {
27-
summary?: string;
28-
title: string;
27+
text: string;
2928
url: string | null;
3029
className?: string;
3130
socialNetworks: ThemeSettings['sharing_actions'];
@@ -36,13 +35,12 @@ interface Props {
3635
}
3736

3837
export function SocialShare({
38+
text,
39+
url,
3940
className,
4041
socialNetworks,
41-
summary,
4242
thumbnailUrl,
43-
title,
4443
trackingContext,
45-
url,
4644
withLabels,
4745
uuid,
4846
}: Props) {
@@ -85,7 +83,7 @@ export function SocialShare({
8583
className={styles.socialLink}
8684
href={createUrlWithQuery('https://www.linkedin.com/sharing/share-offsite', {
8785
url,
88-
text: [title, summary, url].filter(Boolean).join('\n\n'),
86+
text,
8987
})}
9088
onClick={() => trackSharingEvent(SocialNetwork.LINKEDIN)}
9189
rel="noopener noreferrer"
@@ -116,7 +114,7 @@ export function SocialShare({
116114
className={styles.socialLink}
117115
href={createUrlWithQuery('https://twitter.com/intent/tweet', {
118116
url,
119-
text: title,
117+
text,
120118
})}
121119
onClick={() => trackSharingEvent(SocialNetwork.TWITTER)}
122120
rel="noopener noreferrer"
@@ -131,7 +129,7 @@ export function SocialShare({
131129
aria-label={generateAriaLabel(SocialNetwork.MASTODON)}
132130
className={styles.socialLink}
133131
href={createUrlWithQuery('https://mastodon.social/share', {
134-
text: [title, summary, url].filter(Boolean).join('\n\n'),
132+
text: `${text}\n\n${url}`,
135133
})}
136134
onClick={() => trackSharingEvent(SocialNetwork.MASTODON)}
137135
rel="noopener noreferrer"
@@ -148,7 +146,7 @@ export function SocialShare({
148146
href={createUrlWithQuery('https://pinterest.com/pin/create/button/', {
149147
url,
150148
media: thumbnailUrl,
151-
description: [title, summary].filter(Boolean).join(' '),
149+
description: text,
152150
})}
153151
onClick={() => trackSharingEvent(SocialNetwork.PINTEREST)}
154152
rel="noopener noreferrer"
@@ -162,7 +160,7 @@ export function SocialShare({
162160
<a
163161
aria-label={generateAriaLabel(SocialNetwork.REDDIT)}
164162
className={styles.socialLink}
165-
href={createUrlWithQuery('https://www.reddit.com/submit', { title, url })}
163+
href={createUrlWithQuery('https://www.reddit.com/submit', { title: text, url })}
166164
onClick={() => trackSharingEvent(SocialNetwork.REDDIT)}
167165
rel="noopener noreferrer"
168166
target="_blank"
@@ -182,7 +180,7 @@ export function SocialShare({
182180
aria-label={generateAriaLabel(SocialNetwork.WHATSAPP)}
183181
className={styles.socialLink}
184182
href={createUrlWithQuery('https://api.whatsapp.com/send', {
185-
text: `${title} ${url}`,
183+
text: `${text} ${url}`,
186184
})}
187185
onClick={() => trackSharingEvent(SocialNetwork.WHATSAPP)}
188186
rel="noopener noreferrer"
@@ -197,7 +195,7 @@ export function SocialShare({
197195
aria-label={generateAriaLabel(SocialNetwork.THREADS)}
198196
className={styles.socialLink}
199197
href={createUrlWithQuery('https://www.threads.net/intent/post', {
200-
text: `${title} ${url}`,
198+
text: `${text} ${url}`,
201199
})}
202200
onClick={() => trackSharingEvent(SocialNetwork.THREADS)}
203201
rel="noopener noreferrer"
@@ -213,7 +211,7 @@ export function SocialShare({
213211
className={styles.socialLink}
214212
href={createUrlWithQuery('https://t.me/share/url', {
215213
url,
216-
text: title,
214+
text,
217215
})}
218216
onClick={() => trackSharingEvent(SocialNetwork.TELEGRAM)}
219217
rel="noopener noreferrer"
@@ -228,7 +226,7 @@ export function SocialShare({
228226
aria-label={generateAriaLabel(SocialNetwork.BLUESKY)}
229227
className={styles.socialLink}
230228
href={createUrlWithQuery('https://bsky.app/intent/compose', {
231-
text: `${title} ${url}`,
229+
text: `${text} ${url}`,
232230
})}
233231
onClick={() => trackSharingEvent(SocialNetwork.BLUESKY)}
234232
rel="noopener noreferrer"

src/modules/Gallery/Gallery.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ export function Gallery({ localeCode, gallery, href, socialNetworks }: Props) {
3434
socialNetworks.length > 0 &&
3535
href && (
3636
<SocialShare
37-
summary={description ?? undefined}
3837
socialNetworks={socialNetworks}
3938
url={href}
40-
title={name}
39+
text={[name, description].filter(Boolean).join(' - ')}
4140
className={styles.shareLinks}
4241
uuid={uuid}
4342
trackingContext="Gallery"

src/modules/Story/Share/Share.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22

33
import { ACTIONS, DOWNLOAD } from '@prezly/analytics-nextjs';
4-
import type { Story } from '@prezly/sdk';
4+
import type { ExtendedStory, Story } from '@prezly/sdk';
55
import { translations, useIntl } from '@prezly/theme-kit-nextjs/index';
66
import classNames from 'classnames';
77
import { useState } from 'react';
@@ -24,11 +24,11 @@ interface Props {
2424
actions: StoryActions;
2525
socialNetworks: SocialNetwork[];
2626
thumbnailUrl?: string;
27-
title: string;
27+
text: ExtendedStory['social_text'];
28+
title: Story['title'];
2829
url: string | null;
2930
uploadcareAssetsGroupUuid: Story['uploadcare_assets_group_uuid'];
3031
slug: Story['slug'];
31-
summary: Story['summary'];
3232
uuid: Story['uuid'];
3333
}
3434

@@ -37,7 +37,7 @@ export function Share({
3737
uploadcareAssetsGroupUuid,
3838
socialNetworks,
3939
slug,
40-
summary,
40+
text,
4141
title,
4242
thumbnailUrl,
4343
url,
@@ -105,9 +105,8 @@ export function Share({
105105
<SocialShare
106106
socialNetworks={socialNetworks}
107107
url={url}
108-
summary={summary}
108+
text={text}
109109
thumbnailUrl={thumbnailUrl}
110-
title={title}
111110
trackingContext="Story Page Footer"
112111
uuid={uuid}
113112
withLabels={socialShareButtonsCount <= 2}

src/modules/Story/Story.tsx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ export async function Story({
4848
thumbnail_url: thumbnailUrl,
4949
title,
5050
slug,
51-
summary,
5251
uuid,
5352
uploadcare_assets_group_uuid,
5453
} = story;
5554
const nodes = JSON.parse(story.content);
5655
const [headerImageDocument, mainDocument] = pullHeaderImageNode(nodes, withHeaderImage);
56+
const sharingText = story.social_text || story.title;
5757
const sharingUrl = links.short || links.newsroom_view;
5858
const sharingSocialNetworks = getRenderableSocialSharingNetworks(
5959
sharingOptions.sharing_actions,
@@ -98,8 +98,7 @@ export async function Story({
9898
<SocialShare
9999
socialNetworks={sharingSocialNetworks}
100100
url={sharingUrl}
101-
title={title}
102-
summary={summary}
101+
text={sharingText}
103102
uuid={uuid}
104103
thumbnailUrl={thumbnailUrl}
105104
trackingContext="Story Page Header"
@@ -108,19 +107,19 @@ export async function Story({
108107
</div>
109108
<ContentRenderer story={story} nodes={mainDocument} />
110109
</article>
111-
<Share
112-
actions={actions}
113-
thumbnailUrl={thumbnailUrl}
114-
socialNetworks={
115-
sharingOptions.sharing_placement.includes('bottom') ? sharingSocialNetworks : []
116-
}
117-
summary={summary}
118-
slug={slug}
119-
title={title}
120-
uploadcareAssetsGroupUuid={uploadcare_assets_group_uuid}
121-
url={sharingUrl}
122-
uuid={uuid}
123-
/>
110+
{sharingOptions.sharing_placement.includes('bottom') && (
111+
<Share
112+
actions={actions}
113+
thumbnailUrl={thumbnailUrl}
114+
socialNetworks={sharingSocialNetworks}
115+
slug={slug}
116+
title={title}
117+
text={sharingText}
118+
uploadcareAssetsGroupUuid={uploadcare_assets_group_uuid}
119+
url={sharingUrl}
120+
uuid={uuid}
121+
/>
122+
)}
124123
{relatedStories.length > 0 && (
125124
<RelatedStories locale={locale} stories={relatedStories} />
126125
)}

0 commit comments

Comments
 (0)