@@ -6,12 +6,72 @@ import Features from "../components/marketing/features";
66import GetStartedHero from "../components/marketing/get-started-hero" ;
77import Hero from "../components/marketing/hero" ;
88import PricingSection from "../components/marketing/pricing-section" ;
9+ import { createChangesPageClient } from "@changespage/react" ;
10+ import { InferGetStaticPropsType } from "next" ;
911
1012const stripe = require ( "stripe" ) ( process . env . STRIPE_SECRET_KEY ) ;
1113
1214const 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