Skip to content

Commit

Permalink
Simplify homepage logic
Browse files Browse the repository at this point in the history
Simplify homepage logic by hardcoding the guides we want to display on
it. This will ease the transition to Astro v5.

Test plan:
- Confirm homepage content is unchanged
  • Loading branch information
tom-blake committed Dec 5, 2024
1 parent b98d502 commit b63b773
Showing 1 changed file with 32 additions and 52 deletions.
84 changes: 32 additions & 52 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,39 +1,11 @@
---
import BaseLayout from '../layouts/BaseLayout.astro';
import FeaturedContentCard from '../components/FeaturedContentCard.astro';
import { getCollection } from '../utils/getCollection';
import { getEntryBySlug } from 'astro:content';

Check failure on line 4 in src/pages/index.astro

View workflow job for this annotation

GitHub Actions / lint

'getEntryBySlug()' is deprecated. Use 'getEntry()' instead
export async function getStaticPaths() {
const guides = await getCollection('guides');
return guides.map(entry => ({
params: { slug: entry.slug },
props: { entry },
}));
}
function hydrateGuides(featuredGuides, guides) {
return featuredGuides.map((guide) => {
const hydratedGuide = guides.find((g) => g.slug === guide.slug);
return hydratedGuide;
});
}
const guides = await getCollection('guides');
const featuredGuides = hydrateGuides([
{ slug: 'payment-flows' },
{ slug: 'farmlands-portal' },
{ slug: 'farmlands-pos-integration' },
], guides);
const featuredContent = [
{
href: 'https://docs.centrapay.com/api',
title: 'API Reference',
description: 'Powerful, Easy-to-use payment APIs',
img: '/api-reference-cover.jpg',
},
];
const paymentFlowsGuide = await getEntryBySlug('guides', 'payment-flows');
const farmlandsPortal = await getEntryBySlug('guides', 'farmlands-portal');
const farmlandsPosIntegrationGuide = await getEntryBySlug('guides', 'farmlands-pos-integration');
const description = 'Learn to connect with Centrapay experiences.';
const img = '/homepage-preview.png';
Expand Down Expand Up @@ -63,26 +35,34 @@ const img = '/homepage-preview.png';
<h2 class="type-headline-2">Featured Docs</h2>
</div>
<div class="mt-8 grid gap-4 md:grid-cols-2 lg:gap-6">
{ featuredGuides.map((guide) => (
<FeaturedContentCard
title={guide.data.title}
description={guide.data.description}
img={guide.data.img}
slug={guide.slug}
type="guide"
/>
))
}
{ featuredContent.map((content, index) => (
<FeaturedContentCard
title={content.title}
description={content.description}
img={content.img}
href={content.href}
type="api"
/>
))
}
<FeaturedContentCard
title={paymentFlowsGuide.data.title}
description={paymentFlowsGuide.data.description}
img={paymentFlowsGuide.data.img}
slug={paymentFlowsGuide.slug}
type="guide"
/>
<FeaturedContentCard
title={farmlandsPortal.data.title}
description={farmlandsPortal.data.description}
img={farmlandsPortal.data.img}
slug={farmlandsPortal.slug}
type="guide"
/>
<FeaturedContentCard
title={farmlandsPosIntegrationGuide.data.title}
description={farmlandsPosIntegrationGuide.data.description}
img={farmlandsPosIntegrationGuide.data.img}
slug={farmlandsPosIntegrationGuide.id}
type="guide"
/>
<FeaturedContentCard
title="API Reference"
description="Powerful, Easy-to-use payment APIs"
img="/api-reference-cover.jpg"
href="https://docs.centrapay.com/api"
type="api"
/>
</div>
</div>
</BaseLayout>

0 comments on commit b63b773

Please sign in to comment.