A clean, professional Next.js demo showcasing a daily fact website with deterministic daily selection, Pexels API image integration, and Vercel-ready deployment.
- Daily Fact Display: Shows one fact per day with deterministic selection
- No Database Required: Facts stored locally in TypeScript
- Pexels Integration: Fetches relevant images via Pexels API
- Category Constraints: Prevents consecutive days with facts from the same category
- Server-Side Security: Fact data never exposed to client
- TypeScript: Fully typed codebase
- TailwindCSS: Modern styling framework
- Vercel Ready: Optimized for serverless deployment
fact-engine/
├── app/
│ ├── api/
│ │ └── daily-fact/
│ │ └── route.ts # API endpoint for daily fact
│ ├── layout.tsx # Root layout
│ └── page.tsx # Homepage
├── lib/
│ ├── dailyFactService.ts # Daily selection logic
│ ├── facts.ts # Fact storage
│ └── pexels.ts # Pexels API integration
├── types/
│ └── fact.ts # Type definitions
├── styles/
│ └── globals.css # Global styles
├── .env.local.example # Environment variables template
├── .gitignore
├── next.config.js # Next.js configuration
├── package.json
├── postcss.config.js # PostCSS configuration
├── tailwind.config.ts # Tailwind CSS configuration
└── tsconfig.json # TypeScript configuration
npm installCopy the example environment file:
cp .env.local.example .env.local- Visit Pexels API Documentation
- Sign up for a free account
- Create an API key
- Add it to
.env.local:
NEXT_PUBLIC_PEXELS_API_KEY=your_api_key_herenpm run devVisit http://localhost:3000 to see the daily fact.
npm run build
npm start# Pexels API key for image fetching
NEXT_PUBLIC_PEXELS_API_KEY=your_pexels_api_key_hereNote: Because the image fetching happens server-side, the key can safely be exposed as NEXT_PUBLIC_.
Returns the daily fact with an image URL.
Response:
{
"date": "2026-02-26",
"fact": {
"id": "fact-001",
"text": "Honey never spoils...",
"category": "biology",
"imageUrl": "https://images.pexels.com/..."
}
}The daily fact selection uses:
- Deterministic Seeding: Same date always returns the same fact
- Seeded Shuffle: Facts are shuffled using a seed based on date
- Category Constraint: Prevents consecutive days with the same category
- Cycle-Based: When all facts are used, the cycle repeats but maintains determinism
- No Client Exposure: Fact selection logic is server-side only
Facts are stored in lib/facts.ts with the following structure:
interface Fact {
id: string;
text: string;
imageKeyword: string;
category: string;
}Current facts include:
- 12 demo facts
- 5 categories: biology, animals, geography, plants
- Repeated categories for flexible selection
- Git repository initialized
- Vercel account
- Push your code to GitHub (or GitLab/Bitbucket)
- Connect your repository to Vercel
- Add environment variables in Vercel Dashboard:
NEXT_PUBLIC_PEXELS_API_KEY: Your Pexels API key
- Deploy
Vercel automatically detects Next.js and configures the build.
- Framework: Next.js 14 (App Router)
- Language: TypeScript 5
- Styling: TailwindCSS 3
- Image Fetching: Pexels API
- Deployment: Vercel-ready
- No Database: Facts stored as static data for simplicity and cost reduction
- Server-Side Logic: All fact selection happens server-side, never exposing the full dataset
- Seeded RNG: Deterministic shuffle ensures consistency and allows new facts without reshuffling past days
- Image Caching: Pexels API responses cached for 1 hour to reduce API calls
- TypeScript: Full type safety across the codebase
- Vercel Optimization: Uses Next.js Image component and proper caching headers
- Edit lib/facts.ts
- Add new fact objects to the
factsarray - Redeploy
The seeded shuffle ensures that existing dates still show the same facts, while new dates will use the new facts in the rotation.
- Verify
NEXT_PUBLIC_PEXELS_API_KEYis set in.env.local - Check Pexels API key is valid at https://www.pexels.com/api/
- Review browser console for CORS or API errors
This is expected behavior when the fact database is small relative to date range. Increase the number of facts in lib/facts.ts.
- Ensure
NEXT_PUBLIC_PEXELS_API_KEYis in Vercel environment variables - Check TypeScript errors locally with
npm run build - Review Vercel deployment logs
This project is provided as-is for demonstration purposes.