965c090782
- keep homepage section data driven from structured frontmatter - render typed section components inside the template map instead of frontmatter helper code - resolve the Astro parse error in HomePage.astro - preserve the existing homepage section order and component split
70 lines
2.6 KiB
Plaintext
70 lines
2.6 KiB
Plaintext
---
|
|
import { getEntry } from 'astro:content';
|
|
import BaseLayout from '../layouts/BaseLayout.astro';
|
|
import HomeBenefits from './home/HomeBenefits.astro';
|
|
import HomeDirector from './home/HomeDirector.astro';
|
|
import HomeEsa from './home/HomeEsa.astro';
|
|
import HomeFinancialHelp from './home/HomeFinancialHelp.astro';
|
|
import HomeHero from './home/HomeHero.astro';
|
|
import HomeInsurance from './home/HomeInsurance.astro';
|
|
import HomeProcess from './home/HomeProcess.astro';
|
|
import HomeServicesIntro from './home/HomeServicesIntro.astro';
|
|
import HomeSkills from './home/HomeSkills.astro';
|
|
import HomeTestimonials from './home/HomeTestimonials.astro';
|
|
import type { HomePageContent, HomeSection } from '../types/home-sections';
|
|
|
|
interface Props { lang?: string }
|
|
const { lang = 'en' } = Astro.props;
|
|
const es = lang === 'es';
|
|
const entry = await getEntry('pages', es ? 'es/index' : 'en/index');
|
|
if (!entry) throw new Error(`[HomePage] Content entry not found for lang="${lang}". If running in dev, restart the dev server to rebuild the content layer cache.`);
|
|
const { title, description, canonical } = entry.data;
|
|
|
|
function fromHomeContent(home: HomePageContent): HomeSection[] {
|
|
return [
|
|
{ type: 'hero', ...home.hero },
|
|
{ type: 'services-intro', ...home.servicesIntro },
|
|
{ type: 'benefits', ...home.benefits },
|
|
{ type: 'skills', ...home.skills },
|
|
{ type: 'insurance', ...home.insurance },
|
|
{ type: 'esa', ...home.esa },
|
|
{ type: 'financial-help', ...home.financialHelp },
|
|
{ type: 'process', ...home.process },
|
|
{ type: 'director', ...home.director },
|
|
{ type: 'testimonials', ...home.testimonials },
|
|
];
|
|
}
|
|
|
|
const sections: HomeSection[] = entry.data.home
|
|
? fromHomeContent(entry.data.home)
|
|
: ((entry.data.sections ?? []) as HomeSection[]);
|
|
---
|
|
<BaseLayout {title} {description} {canonical} {lang}>
|
|
{sections.map((section) => {
|
|
switch (section.type) {
|
|
case 'hero':
|
|
return <HomeHero section={section} />;
|
|
case 'services-intro':
|
|
return <HomeServicesIntro section={section} />;
|
|
case 'benefits':
|
|
return <HomeBenefits section={section} />;
|
|
case 'skills':
|
|
return <HomeSkills section={section} />;
|
|
case 'insurance':
|
|
return <HomeInsurance section={section} />;
|
|
case 'esa':
|
|
return <HomeEsa section={section} />;
|
|
case 'financial-help':
|
|
return <HomeFinancialHelp section={section} />;
|
|
case 'process':
|
|
return <HomeProcess section={section} />;
|
|
case 'director':
|
|
return <HomeDirector section={section} />;
|
|
case 'testimonials':
|
|
return <HomeTestimonials section={section} />;
|
|
default:
|
|
return null;
|
|
}
|
|
})}
|
|
</BaseLayout>
|