cooking/lib/recipe-urls.ts
2026-09-13 14:50:11 -07:00

18 lines
612 B
TypeScript

// Client-safe URL helpers (no fs imports)
interface RecipeLocation {
category: string;
slug: string;
}
// Rewrites a recipe-relative path like "./assets/hero.jpg" to its served URL
export function resolveRecipeAssetUrl(recipe: RecipeLocation, src: string): string {
if (!src.startsWith('./')) return src;
return `/recipes/${recipe.category}/${recipe.slug}/${src.slice(2)}`;
}
// Generated recipe card image, e.g. "card.png" or "front.png"
export function recipeCardImageUrl(recipe: RecipeLocation, fileName: string): string {
return `/recipes/${recipe.category}/${recipe.slug}/card/${fileName}`;
}