A Next.js (Pages Router) front-end that renders pages composed in Contentful, modeled after onstar.com.
-
Install dependencies
npm install
-
Configure environment variables
Copy
.env.exampleto.env.localand fill in your Contentful credentials:cp .env.example .env.local
Variable Description CONTENTFUL_SPACE_IDYour Contentful space ID CONTENTFUL_ACCESS_TOKENContent Delivery API token CONTENTFUL_PREVIEW_TOKENContent Preview API token CONTENTFUL_ENVIRONMENTEnvironment name (default: master) -
Create a home page in Contentful
Create a Page entry with slug
home. Add section entries (Hero Banner, Card Row, etc.) to the page'ssectionsfield. -
Run the dev server
npm run dev
Open http://localhost:3000.
src/
├── components/
│ ├── sections/ # One component per Contentful section type
│ │ ├── HeroBanner.tsx
│ │ ├── PromoBanner.tsx
│ │ ├── CardRow.tsx
│ │ ├── PlanComparison.tsx
│ │ ├── FaqSection.tsx
│ │ ├── TestimonialSection.tsx
│ │ ├── RichTextSection.tsx
│ │ └── VehicleShowcase.tsx
│ ├── ui/ # Reusable primitives
│ │ ├── ContentfulImage.tsx
│ │ └── Cta.tsx
│ ├── Footer.tsx
│ ├── Layout.tsx
│ ├── Navigation.tsx
│ └── SectionRenderer.tsx
├── lib/
│ ├── contentful.ts # Contentful client & data fetching
│ ├── helpers.ts # Type guards & image URL builder
│ └── types.ts # TypeScript types for every content type
├── pages/
│ ├── _app.tsx
│ ├── _document.tsx
│ ├── index.tsx # Renders the "home" page
│ └── [slug].tsx # Renders any other page by slug
└── styles/
└── globals.css
Every page in Contentful has a slug and an array of sections. The SectionRenderer maps each section's content type ID to the corresponding React component. Adding a new section type is as simple as creating the component and registering it in SectionRenderer.tsx.
Pages are statically generated at build time via getStaticProps and revalidated every 60 seconds (ISR). The [slug].tsx catch-all uses fallback: "blocking" so new pages published in Contentful are rendered on first request.