diff --git a/README.md b/README.md index ce0c1d9..0974d39 100644 --- a/README.md +++ b/README.md @@ -79,18 +79,23 @@ lunch: chipotle bowl dinner: Lemon Couscous w Salmon and roast broccoli ``` -the justfile contains scrips for creating a `.rem` file for remind(1). -(from there you can use the `rem2ics` utility to create a calendar file, -or `rem2ps` to create a pdf.) -it also can create a simple pdf menu via groff and tbl. -finally it print a list of ingredients needed for next week's menu -so you can plan your shoping. +Scrips: + +- the justfile contains scrips for creating a `.rem` file for remind(1). + (from there you can use the `rem2ics` utility to create a calendar file, + or `rem2ps` to create a pdf.) + +- `/bin/pdf.sh` + will create a simple pdf menu via groff and tbl. + +- `/bin/indredients.sh` + will print a list of ingredients based on the week's menu + so you can plan your shoping. ## YOU WILL NEED - recutils - groff -- zx ## GETTING STARTED @@ -103,7 +108,7 @@ so you can plan your shoping. This might eventually become part of the backend for supervegan.neocities.org -- [ ] remove zx dep (i thought it would make dates easier in the beginning) -- [ ] parameterize the date for which the week should be calculated. +- [x] remove zx dep (i thought it would make dates easier in the beginning) +- [x] parameterize the date for which the week should be calculated. - [ ] quantity for recipe ingredient? - [ ] yield for recipe? diff --git a/bin/ingredients.sh b/bin/ingredients.sh new file mode 100644 index 0000000..5c3a369 --- /dev/null +++ b/bin/ingredients.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env sh +if [ $# -eq 0 ] +then + begin=$(gdate -d'Last Sun') + end=$(gdate -d'Last Sun +6 days') +else + mydate=$1 + shift + begin=`gdate -d "$mydate -$(gdate --date="$mydate" +%u) days"` + end=`gdate -d "$begin" -d'+7 days'` +fi + +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 + diff --git a/bin/pdf.sh b/bin/pdf.sh new file mode 100644 index 0000000..20b7962 --- /dev/null +++ b/bin/pdf.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env sh +if [ $# -eq 0 ] +then + mydate=$(gdate) +else + mydate=$1 + shift +fi + + +firstday=`gdate -d "$mydate -$(gdate --date="$mydate" +%u) days" +%F` +lastday=`gdate -d "$firstday +6 days" +%F` +firstdayout=`gdate -d"$firstday +1 days" +%F` +lastdayout=`gdate -d"$firstday +5 days" +%d` +firstdaygroff=`gdate -d"$firstday +1 days" +"%B %_d, %Y"` +lastdaygroff=`gdate -d"$firstday +5 days" +"%B %_d, %Y"` + + +tmpl=$( +cat<> '$firstday'" \ +| recsel -e "date << '$lastday'" \ +| recsel -p breakfast \ +| recfmt '.ad l +{{breakfast}} +T};T{ +' +) +T} +.sp +Lunch;T{ +$( +recsel db/menu.rec -e "date >> '$firstday'" \ +| recsel -e "date << '$lastday'" \ +| recsel -p lunch \ +| recfmt '.ad l +{{lunch}} +T};T{ +' +) +T} +.sp +Dinner;T{ +$( +recsel db/menu.rec -e "date >> '$firstday'" \ +| recsel -e "date << '$lastday'" \ +| recsel -p dinner \ +| recfmt '.ad l +{{dinner}} +T};T{ +' +) +T} +.TE +EOF +) + + +echo "$tmpl" \ +| groff -t -ms -Tpdf -d paper=letterl -P-pletterl \ +> dist/"$firstdayout"-"$lastdayout".pdf + diff --git a/dist/2024-01-29-02.pdf b/dist/2024-01-29-02.pdf index ebaeb0e..91d44b4 100644 Binary files a/dist/2024-01-29-02.pdf and b/dist/2024-01-29-02.pdf differ diff --git a/dist/2024-02-05-09.pdf b/dist/2024-02-05-09.pdf index 0ac633b..6ef456d 100644 Binary files a/dist/2024-02-05-09.pdf and b/dist/2024-02-05-09.pdf differ diff --git a/justfile b/justfile index b102af1..7010490 100644 --- a/justfile +++ b/justfile @@ -16,85 +16,11 @@ rem: # 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`) + sh bin/pdf.sh # 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 + sh bin/ingredients.sh