meals/justfile

101 lines
2.4 KiB
Plaintext

# show all recipes
default:
just --list --unsorted
remtmpl := '''
"rem {{date}} at 08:00 tag breakfast msg {{breakfast}}%
rem {{date}} at 12:00 tag lunch msg {{lunch}}%
rem {{date}} at 18:00 tag dinner msg {{dinner}}%
"'''
# build menu.rem from menu.rec
rem:
#!/bin/sh
exec > dist/menu.rem
recsel db/menu.rec | recfmt {{remtmpl}}
# build menu pdf from menu.rec
pdf:
#!/usr/bin/env zx
const curr = new Date()
const firstday = new Date(curr.setDate(curr.getDate() - curr.getDay()));
const lastday = new Date(curr.setDate(curr.getDate() - curr.getDay()+6));
const options = {
year: "numeric",
month: "long",
day: "numeric",
};
const rec = await $`recsel db/menu.rec -e ${'date >> "' + firstday + '"'}`.quiet()
.pipe($`recsel -e ${'date << "' + lastday + '"'}`).quiet()
const bkfst = await $`echo ${rec}`.quiet()
.pipe($`recsel -p breakfast`).quiet()
.pipe($`recfmt '.ad l
{{{{breakfast}}
T};T{
'`).quiet()
const lunch = await $`echo ${rec}`.quiet()
.pipe($`recsel -p lunch`).quiet()
.pipe($`recfmt '.ad l
{{{{lunch}}
T};T{
'`).quiet()
const dinner = await $`echo ${rec}`.quiet()
.pipe($`recsel -p dinner`).quiet()
.pipe($`recfmt '.ad l
{{{{dinner}}
T};T{
'`).quiet()
const firstdaygroff = new Date(firstday.setDate(firstday.getDate()+1 - firstday.getDay())).toLocaleString('en-US', options);
const lastdaygroff = new Date(lastday.setDate(lastday.getDate() - lastday.getDay()+5)).toLocaleString('en-US', options);
const tmpl=`
.ce
.I
chez brun
.sp 2
.LP
.ps 14
${firstdaygroff} - ${lastdaygroff}
.ps
.sp 3
.LP
.TS
center expand tab(;);
l | lp+2 lp+2 lp+2 lp+2 lp+2
- | - - - - -
l | l l l l l.
;Monday;Tuesday;Wednesday;Thursday;Friday
Breakfast;T{
${bkfst}
T}
.sp
Lunch;T{
${lunch}
T}
.sp
Dinner;T{
${dinner}
T}
.TE`
await $`echo ${tmpl}`.quiet()
.pipe($`groff -t -ms -Tpdf -d paper=letterl -P-pletterl > dist/${new Date(firstdaygroff).toISOString().slice(0, 10)}-${new Date(lastdaygroff).toISOString().slice(8,10)}.pdf`)
# build menus!
menu: rem pdf
# shopping list
shopping:
#!/usr/bin/env sh
begin=$(gdate -d'next sun')
end=$(gdate -d'next sun +7 days')
recsel db/menu.rec -e "date >> '$begin'" \
| recsel -e "date << '$end'" -P breakfast,lunch,dinner -C \
| sort \
| uniq \
| xargs -I % recsel db/recipes.rec \
-t meal \
-j recipe \
-e "name = '%'" \
-G name \
-P recipe_ingredient \
| sort