A static site generator (SSG) built with Astro and TypeScript for planning weekly menus based on food science principles.
how-not-to-diet/
├── src/
│ ├── components/ # Reusable UI components
│ │ └── RecipeCard.astro
│ ├── layouts/ # Page layout templates
│ │ └── Layout.astro
│ ├── pages/ # Route pages (file-based routing)
│ │ └── index.astro
│ ├── types/ # TypeScript type definitions
│ │ └── index.ts
│ └── utils/ # Helper functions and utilities
│ ├── dataLoader.ts # Functions to load JSON data
│ └── helpers.ts # General utility functions
├── data/ # JSON data files
│ ├── recipes.json # Recipe database
│ └── weekly-menus.json # Weekly menu plans
├── public/ # Static assets (served as-is)
│ └── favicon.svg
├── .gitignore
├── astro.config.mjs # Astro configuration
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
└── README.md
- Astro 4.16.12: Modern static site generator with partial hydration
- TypeScript 5.7.2: Full type safety across the project
- Zero JavaScript by default: Pages ship pure HTML/CSS unless components need interactivity
- Strict mode enabled for maximum type safety
- Path aliases configured for clean imports:
@components/*→src/components/*@layouts/*→src/layouts/*@utils/*→src/utils/*@data/*→data/*@types/*→src/types/*
- Output mode: Static (pre-rendered at build time)
- Dev server: Runs on port 3000
- Build optimization: Auto-inlining of stylesheets
- Path aliases mirrored from TypeScript config
The project uses a comprehensive type system defined in src/types/index.ts:
Recipe: Complete recipe information including ingredients, instructions, nutritionIngredient: Structured ingredient data with amounts and unitsNutritionInfo: Nutritional facts per servingWeeklyMenu: Weekly meal planning structureDayMenu: Daily meal organizationShoppingListItem: Generated shopping list items
The src/utils/dataLoader.ts provides functions to:
- Load all recipes or specific recipes by ID
- Filter recipes by category
- Load weekly menu plans
- Search recipes by query string
The src/utils/helpers.ts includes:
- Time formatting (minutes to human-readable)
- Nutrition calculation for daily meals
- Shopping list generation from recipes
- Date formatting utilities
- Responsive navigation header
- Clean, semantic HTML structure
- Scoped CSS with CSS custom properties for theming
- Color scheme based on food/health theme (greens)
- Mobile-first responsive design
- Displays recipe summary or full details
- Shows prep/cook time, servings, nutrition facts
- Tag system for categorization
- Optional detailed view with ingredients and instructions
- Hover effects for better UX
The project includes example data:
- recipes.json: 2 sample recipes (Berry Oatmeal Bowl, Mediterranean Chickpea Salad)
- weekly-menus.json: Template weekly menu structure
npm installnpm run devVisit http://localhost:3000 to see your site.
npm run buildGenerates static files in the dist/ directory.
npm run previewnpm run type-check- Static Site Generation: Chosen for optimal performance, SEO, and hosting simplicity
- TypeScript: Ensures type safety for data structures, especially important for recipe/nutrition data
- Component-based Architecture: Promotes reusability and maintainability
- JSON Data Storage: Easy to edit, version control, and eventually migrate to a CMS
- Path Aliases: Cleaner imports and better developer experience
- Scoped Styling: Prevents CSS conflicts and keeps styles component-focused
- Semantic HTML: Improves accessibility and SEO
- Mobile-First Design: Ensures good experience on all devices
To expand this project, consider:
-
Add more pages:
/menu- Display weekly menu/recipes- Browse all recipes/recipes/[id]- Individual recipe pages
-
Add interactivity:
- Shopping list generator
- Meal planner interface
- Recipe search/filter
-
Enhance data:
- Add more recipes from the cookbook
- Create multiple weekly menu templates
- Add ingredient categories for shopping organization
-
Improve UX:
- Add images for recipes
- Implement print-friendly styles
- Add nutritional goal tracking
-
Deploy:
- Deploy to Netlify, Vercel, or GitHub Pages
- Set up CI/CD pipeline
- PDF cookbook is excluded from git (see
.gitignore) - No external UI libraries added to keep bundle small
- Can easily integrate React, Vue, or Svelte components if needed later
- All styling uses vanilla CSS with modern features (Grid, Flexbox, Custom Properties)