Skip to content

Commit 161401d

Browse files
Add newsletter setting for footer Share button (#26868)
ref https://linear.app/ghost/issue/FEA-480/native-share-buttons-with-link-based-referral-param-for-attribution Adds a newsletter setting to show/hide the footer Share action and updates the settings preview footer actions UI to match the email layout. --------- Co-authored-by: Troy Ciesco <tmciesco@gmail.com>
1 parent a1e2460 commit 161401d

File tree

10 files changed

+131
-332
lines changed

10 files changed

+131
-332
lines changed

apps/admin-x-framework/src/api/newsletters.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export type Newsletter = {
3030
show_header_name: boolean;
3131
show_post_title_section: boolean;
3232
show_comment_cta: boolean;
33+
show_share_button: boolean;
3334
show_subscription_details: boolean;
3435
show_latest_posts: boolean;
3536
background_color: string;

apps/admin-x-framework/src/test/responses/newsletters.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"show_header_name": true,
2929
"show_post_title_section": true,
3030
"show_comment_cta": true,
31+
"show_share_button": false,
3132
"show_subscription_details": false,
3233
"show_latest_posts": false,
3334
"background_color": "light",
@@ -76,6 +77,7 @@
7677
"show_header_name": true,
7778
"show_post_title_section": true,
7879
"show_comment_cta": true,
80+
"show_share_button": false,
7981
"show_subscription_details": false,
8082
"show_latest_posts": false,
8183
"background_color": "light",

apps/admin-x-settings/src/components/settings/email/newsletters/newsletter-detail-modal.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,12 @@ const Sidebar: React.FC<{
372372
label='Add a link to your comments'
373373
onChange={e => updateNewsletter({show_comment_cta: e.target.checked})}
374374
/>}
375+
<Toggle
376+
checked={newsletter.show_share_button}
377+
direction="rtl"
378+
label='Show share button'
379+
onChange={e => updateNewsletter({show_share_button: e.target.checked})}
380+
/>
375381
<Toggle
376382
checked={newsletter.show_latest_posts}
377383
direction="rtl"

apps/admin-x-settings/src/components/settings/email/newsletters/newsletter-preview-content.tsx

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const NewsletterPreviewContent: React.FC<{
2626
showCommentCta: boolean;
2727
showFeatureImage: boolean;
2828
showFeedback: boolean;
29+
showShareButton: boolean;
2930
showLatestPosts: boolean;
3031
showSubscriptionDetails: boolean;
3132

@@ -70,6 +71,7 @@ const NewsletterPreviewContent: React.FC<{
7071
showCommentCta,
7172
showFeatureImage,
7273
showFeedback,
74+
showShareButton,
7375
showLatestPosts,
7476
showSubscriptionDetails,
7577

@@ -266,32 +268,40 @@ const NewsletterPreviewContent: React.FC<{
266268
</div>
267269

268270
{/* Feedback */}
269-
{(showFeedback || showCommentCta) && (
271+
{(showFeedback || showCommentCta || showShareButton) && (
270272
<div className={clsx('grid gap-5 border-b border-grey-200 px-6 py-5', dividerStyle === 'dashed' && 'border-dashed', dividerStyle === 'dotted' && 'border-b-2 border-dotted')} style={{borderColor: dividerColor}}>
271-
<div className="flex justify-center gap-3">
273+
<div className="grid auto-cols-fr grid-flow-col gap-4">
272274
{showFeedback && (
273275
<>
274-
<button className="pointer-events-none cursor-default rounded-[2.2rem] bg-transparent font-semibold whitespace-nowrap" type="button">
275-
<span className="inline-flex items-center gap-2 px-[18px] py-[7px]" style={{color: textColor}}>
276+
<div className="pointer-events-none flex min-w-[120px] cursor-default flex-col items-center gap-[11px] text-center">
277+
<span className="inline-flex size-[54px] items-center justify-center rounded-full border" style={{borderColor: dividerColor, color: textColor}}>
276278
<Icon colorClass='' name="thumbs-up" size="md" />
277-
<span>More like this</span>
278279
</span>
279-
</button>
280-
<button className="pointer-events-none cursor-default rounded-[2.2rem] bg-transparent font-semibold whitespace-nowrap" type="button">
281-
<span className="inline-flex items-center gap-2 px-[18px] py-[7px]" style={{color: textColor}}>
282-
<Icon colorClass='' name="thumbs-down" />
283-
<span>Less like this</span>
280+
<span className="font-sans text-[1.3rem] leading-[1.4] font-medium" style={{color: textColor}}>More like this</span>
281+
</div>
282+
<div className="pointer-events-none flex min-w-[120px] cursor-default flex-col items-center gap-[11px] text-center">
283+
<span className="inline-flex size-[54px] items-center justify-center rounded-full border" style={{borderColor: dividerColor, color: textColor}}>
284+
<Icon colorClass='' name="thumbs-down" size="md" />
284285
</span>
285-
</button>
286+
<span className="font-sans text-[1.3rem] leading-[1.4] font-medium" style={{color: textColor}}>Less like this</span>
287+
</div>
286288
</>
287289
)}
288290
{showCommentCta && (
289-
<button className="pointer-events-none cursor-default rounded-[2.2rem] bg-transparent font-semibold whitespace-nowrap" type="button">
290-
<span className="inline-flex items-center gap-2 px-[18px] py-[7px]" style={{color: textColor}}>
291-
<Icon colorClass='' name="comment" />
292-
<span>Comment</span>
291+
<div className="pointer-events-none flex min-w-[120px] cursor-default flex-col items-center gap-[11px] text-center">
292+
<span className="inline-flex size-[54px] items-center justify-center rounded-full border" style={{borderColor: dividerColor, color: textColor}}>
293+
<Icon colorClass='' name="comment" size="md" />
293294
</span>
294-
</button>
295+
<span className="font-sans text-[1.3rem] leading-[1.4] font-medium" style={{color: textColor}}>Comment</span>
296+
</div>
297+
)}
298+
{showShareButton && (
299+
<div className="pointer-events-none flex min-w-[120px] cursor-default flex-col items-center gap-[11px] text-center">
300+
<span className="inline-flex size-[54px] items-center justify-center rounded-full border" style={{borderColor: dividerColor, color: textColor}}>
301+
<Icon colorClass='' name="share" size="md" />
302+
</span>
303+
<span className="font-sans text-[1.3rem] leading-[1.4] font-medium" style={{color: textColor}}>Share</span>
304+
</div>
295305
)}
296306
</div>
297307
</div>

apps/admin-x-settings/src/components/settings/email/newsletters/newsletter-preview.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const NewsletterPreview: React.FC<{newsletter: Newsletter}> = ({newsletter}) =>
2121

2222
const showCommentCta = newsletter.show_comment_cta && commentsEnabled !== 'off';
2323
const showFeedback = newsletter.feedback_enabled;
24+
const showShareButton = newsletter.show_share_button;
2425

2526
const backgroundColor = () => {
2627
const value = newsletter.background_color;
@@ -207,6 +208,7 @@ const NewsletterPreview: React.FC<{newsletter: Newsletter}> = ({newsletter}) =>
207208
showFeedback={showFeedback}
208209
showLatestPosts={newsletter.show_latest_posts}
209210
showPostTitleSection={newsletter.show_post_title_section}
211+
showShareButton={showShareButton}
210212
showSubscriptionDetails={newsletter.show_subscription_details}
211213
siteTitle={title}
212214
titleAlignment={newsletter.title_alignment}

ghost/core/core/server/services/email-service/email-renderer.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,7 @@ class EmailRenderer {
10321032

10331033
const postUrl = this.#getPostUrl(post);
10341034
const isPublicPost = post.get('visibility') === 'public';
1035+
const showShareButton = isPublicPost && newsletter.get('show_share_button');
10351036
const shareUrl = new URL(postUrl);
10361037
shareUrl.hash = '/share';
10371038

@@ -1059,7 +1060,7 @@ class EmailRenderer {
10591060
const hasEmailOnlyFlag = post.related('posts_meta')?.get('email_only') ?? false;
10601061
const hasFeedbackButtons = newsletter.get('feedback_enabled');
10611062
const showCommentCta = newsletter.get('show_comment_cta') && this.#settingsCache.get('comments_enabled') !== 'off' && !hasEmailOnlyFlag;
1062-
const feedbackButtonCount = (hasFeedbackButtons ? 2 : 0) + (showCommentCta ? 1 : 0) + (isPublicPost ? 1 : 0);
1063+
const feedbackButtonCount = (hasFeedbackButtons ? 2 : 0) + (showCommentCta ? 1 : 0) + (showShareButton ? 1 : 0);
10631064
const feedbackButtonCellWidth = feedbackButtonCount > 0
10641065
? `${(100 / feedbackButtonCount).toFixed(2).replace(/\.00$/, '')}%`
10651066
: null;
@@ -1123,7 +1124,7 @@ class EmailRenderer {
11231124
post: {
11241125
title: post.get('title'),
11251126
url: postUrl,
1126-
shareUrl: isPublicPost ? shareUrl.href : null,
1127+
shareUrl: showShareButton ? shareUrl.href : null,
11271128
commentUrl: commentUrl.href,
11281129
authors,
11291130
publishedAt,

0 commit comments

Comments
 (0)