Skip to content

Commit

Permalink
Enable Black Friday discount
Browse files Browse the repository at this point in the history
  • Loading branch information
sapegin committed Nov 25, 2024
1 parent 58cf173 commit 50cd85a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 13 deletions.
17 changes: 17 additions & 0 deletions src/campaigns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export interface Campaign {
enabled: boolean;
badge: string;
price: number;
discountedPrice: number;
url: string;
}

export const campaigns: Record<string, Campaign> = {
washingCode: {
enabled: true,
badge: 'Now 75% off!',
price: 20,
discountedPrice: 5,
url: 'https://sapegin.gumroad.com/l/washingcode-book/blackest',
},
};
10 changes: 9 additions & 1 deletion src/components/BookLink.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { BookCover, Box, QuotedLink, Stack, Text } from '.';
import type { Resource } from '../types/Resource';
import { campaigns } from '../campaigns';

function getCampaign(url: string) {
if (url === '/book/') {
return campaigns.washingCode.enabled ? campaigns.washingCode : undefined;
}
}

type Props = {
book: Resource;
};

export function BookLink({ book: { url, image, title, description } }: Props) {
const campaign = url ? getCampaign(url) : undefined;
return (
<QuotedLink key={url} href={url} display="block">
<Stack gap="m" direction="row">
Expand All @@ -15,7 +23,7 @@ export function BookLink({ book: { url, image, title, description } }: Props) {
</Box>
)}
<Stack direction="column" gap="s">
{url === '/book/' && <Text variant="flag">Just launched!</Text>}
{campaign && <Text variant="flag">{campaign.badge}</Text>}
<Text as="u" variant="large">
{title}
</Text>
Expand Down
3 changes: 1 addition & 2 deletions src/components/BookPostFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ export function BookPostFooter() {
If you have any feedback, drop me a line at
</Feedback>
<Text>
<Link href="/book/">Get the book now</Link> with 50% launch
discount!
<Link href="/book/">Get the book now!</Link>
</Text>
</Stack>
<Link href="/book/">
Expand Down
8 changes: 5 additions & 3 deletions src/components/BookPostHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { Stack, Text, Link, BookCover, PostAddon } from '.';
import { campaigns } from '../campaigns';

const { enabled: isCampaignEnabled, badge } = campaigns.washingCode;

export function BookPostHeader() {
return (
<PostAddon>
<Stack direction="row" gap="m">
<Stack gap="m">
<Text variant="flag">Just launched!</Text>
{isCampaignEnabled && <Text variant="flag">{badge}</Text>}
<Text variant="intro">
You’re reading an excerpt of my upcoming book on clean code for
frontend developers, “Washing your code.”
</Text>
<Text>
<Link href="/book/">Get the book now</Link> with 50% launch
discount!
<Link href="/book/">Get the book now!</Link>
</Text>
</Stack>
<Link href="/book/">
Expand Down
25 changes: 18 additions & 7 deletions src/templates/BookPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ import {
import type { Chapter } from '../types/Chapter';
import { Page } from './Page';
import { Markdown } from '../components/Markdown';
import { campaigns } from '../campaigns';

const {
enabled: isCampaignEnabled,
badge,
price,
discountedPrice,
url: purchaseUrl,
} = campaigns.washingCode;

type Props = {
url: string;
Expand Down Expand Up @@ -146,16 +155,18 @@ const faq: FaqItem[] = [

function TheButton() {
return (
<Button
as="a"
variant="large"
href="https://sapegin.gumroad.com/l/washingcode-book/rocket"
>
<Button as="a" variant="large" href={purchaseUrl}>
Get the book!{' '}
<Box as="span" px="s" verticalAlign="middle" fontSize="s">
</Box>{' '}
<del>€20</del> €10
{isCampaignEnabled ? (
<>
<del>{price}</del>{discountedPrice}
</>
) : (
<>{price}</>
)}
</Button>
);
}
Expand Down Expand Up @@ -393,7 +404,7 @@ export function BookPage({ url, chapters, patterns, antipatterns }: Props) {
<Page url={url}>
<Stack gap="xl">
<Stack gap="s">
<Text variant="flag">Just launched!</Text>
{isCampaignEnabled && <Text variant="flag">{badge}</Text>}
<Heading level={1}>Washing your code</Heading>
<Heading level={3} as="p">
A book on clean code for frontend developers
Expand Down

0 comments on commit 50cd85a

Please sign in to comment.