- remove zx
- parameterize the date for pdf and ingredient scripts
main
dozens 2024-02-03 17:53:22 -07:00
parent ed8c8d64ea
commit 649ccb033c
6 changed files with 120 additions and 85 deletions

View File

@ -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?

24
bin/ingredients.sh 100644
View File

@ -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

80
bin/pdf.sh 100644
View File

@ -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<<EOF
.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{
$(
recsel db/menu.rec -e "date >> '$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

BIN
dist/2024-01-29-02.pdf vendored

Binary file not shown.

BIN
dist/2024-02-05-09.pdf vendored

Binary file not shown.

View File

@ -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