Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/lowmess/lameass.recipes. A recipe site, but without the ads and 3,000 word essays lameass.recipes
nextjs sanity-io theme-ui typescript
Something went wrong. Try again.
1.2 kB · 60 lines
TypeScript
at develop
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061import smartypants from '../utils/smartypants'import mdToHTML from '../utils/markdown'import { Meal, Recipe } from '../types/api'
interface RawMeal extends Meal { recipes: Recipe[]}
const formatMeal = (meal: RawMeal): Meal => { const recipes = meal.recipes.map((recipe) => ({ _id: recipe._id, title: smartypants(recipe.title), slug: recipe.slug, }))
const emojis = Array.from( new Set(meal.recipes.map((recipe) => recipe.category.emoji)) )
const tags = meal.recipes .flatMap((r) => r.tags) .filter((t) => t) .reduce((acc, cur) => { const newTags = [...acc]
const exists = acc.find((tag) => tag.slug === cur.slug)
if (!exists) newTags.push(cur)
return newTags }, [])
const sections = meal.sections ? meal.sections.map((section) => { const steps = section.steps.map((step) => mdToHTML(step, { inline: true, allowLineBreaks: true }) )
return { ...section, title: smartypants(section.title), steps, } }) : []
const description = meal.description ? mdToHTML(meal.description) : null
return { ...meal, title: smartypants(meal.title), description, emojis, tags, recipes, sections, }}
export default formatMeal