Skip to content

Commit 8efb6a2

Browse files
committed
Show latest post in landing page
1 parent 0a111bc commit 8efb6a2

File tree

2 files changed

+75
-51
lines changed

2 files changed

+75
-51
lines changed

apps/web/components/marketing/hero.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ import Link from "next/link";
44
import { ROUTES } from "../../data/routes.data";
55
import capture from "../../public/images/hero/capture.png";
66
import appLogo from "../../public/images/logo.png";
7+
import { Post } from "@changespage/react";
78
const version = require("../../package.json").version;
89

9-
export default function Hero({ stars = null }: { stars?: string | null }) {
10+
export default function Hero({
11+
stars = null,
12+
latestPost = null,
13+
}: {
14+
stars?: string | null;
15+
latestPost: Post | null;
16+
}) {
1017
return (
1118
<div className="relative isolate overflow-hidden bg-gray-900">
1219
<svg
@@ -83,7 +90,11 @@ export default function Hero({ stars = null }: { stars?: string | null }) {
8390
What&apos;s new
8491
</span>
8592
<span className="inline-flex items-center space-x-2 text-sm font-medium leading-6 text-gray-300">
86-
<span>Just shipped v{version}</span>
93+
{latestPost ? (
94+
<span>{latestPost.title}</span>
95+
) : (
96+
<span>Just shipped v{version}</span>
97+
)}
8798
<ChevronRightIcon
8899
className="h-5 w-5 text-gray-500"
89100
aria-hidden="true"

apps/web/pages/index.tsx

Lines changed: 62 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,72 @@ import Features from "../components/marketing/features";
66
import GetStartedHero from "../components/marketing/get-started-hero";
77
import Hero from "../components/marketing/hero";
88
import PricingSection from "../components/marketing/pricing-section";
9+
import { createChangesPageClient } from "@changespage/react";
10+
import { InferGetStaticPropsType } from "next";
911

1012
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
1113

1214
const FAQs = dynamic(() => import("../components/marketing/faq"));
1315

14-
export default function Index({ addons, unit_amount, stars }) {
16+
async function getGitHubStars(): Promise<string | null> {
17+
try {
18+
const response = await fetch(
19+
"https://api.github.com/repos/techulus/changes-page",
20+
{
21+
headers: {
22+
Accept: "application/vnd.github+json",
23+
},
24+
}
25+
);
26+
27+
if (!response?.ok) {
28+
return null;
29+
}
30+
31+
const json = await response.json();
32+
33+
return parseInt(json.stargazers_count, 10).toLocaleString();
34+
} catch {
35+
return null;
36+
}
37+
}
38+
39+
export async function getStaticProps() {
40+
const { unit_amount } = await stripe.prices.retrieve(
41+
process.env.STRIPE_PRICE_ID
42+
);
43+
const { unit_amount: email_unit_amount } = await stripe.prices.retrieve(
44+
process.env.EMAIL_NOTIFICATION_STRIPE_PRICE_ID
45+
);
46+
const stars = await getGitHubStars();
47+
48+
const client = createChangesPageClient({
49+
baseUrl: "https://hey.changes.page",
50+
});
51+
const latestPost = await client.getLatestPost();
52+
53+
return {
54+
props: {
55+
unit_amount,
56+
addons: [
57+
{
58+
name: "email notification",
59+
price: email_unit_amount / 100,
60+
},
61+
],
62+
stars,
63+
latestPost,
64+
},
65+
revalidate: 86400,
66+
};
67+
}
68+
69+
export default function Index({
70+
addons,
71+
unit_amount,
72+
stars,
73+
latestPost,
74+
}: InferGetStaticPropsType<typeof getStaticProps>) {
1575
return (
1676
<div className="h-full dark:bg-gray-800">
1777
<Head>
@@ -127,7 +187,7 @@ export default function Index({ addons, unit_amount, stars }) {
127187

128188
<main>
129189
<section>
130-
<Hero stars={stars} />
190+
<Hero stars={stars} latestPost={latestPost} />
131191
</section>
132192
<Features />
133193
<PricingSection addons={addons} unit_amount={unit_amount} />
@@ -139,50 +199,3 @@ export default function Index({ addons, unit_amount, stars }) {
139199
</div>
140200
);
141201
}
142-
143-
async function getGitHubStars(): Promise<string | null> {
144-
try {
145-
const response = await fetch(
146-
"https://api.github.com/repos/techulus/changes-page",
147-
{
148-
headers: {
149-
Accept: "application/vnd.github+json",
150-
},
151-
}
152-
);
153-
154-
if (!response?.ok) {
155-
return null;
156-
}
157-
158-
const json = await response.json();
159-
160-
return parseInt(json.stargazers_count, 10).toLocaleString();
161-
} catch {
162-
return null;
163-
}
164-
}
165-
166-
export async function getStaticProps() {
167-
const { unit_amount } = await stripe.prices.retrieve(
168-
process.env.STRIPE_PRICE_ID
169-
);
170-
const { unit_amount: email_unit_amount } = await stripe.prices.retrieve(
171-
process.env.EMAIL_NOTIFICATION_STRIPE_PRICE_ID
172-
);
173-
const stars = await getGitHubStars();
174-
175-
return {
176-
props: {
177-
unit_amount,
178-
addons: [
179-
{
180-
name: "email notification",
181-
price: email_unit_amount / 100,
182-
},
183-
],
184-
stars,
185-
},
186-
revalidate: 86400,
187-
};
188-
}

0 commit comments

Comments
 (0)