Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { formatMenuLines } from "https://esm.town/v/tal/formatMenuLines";
import { DOEMenuTypes } from "https://esm.town/v/tal/DOEMenuTypes";
type Line = {
dateStr: string;
menuStr: string;
date: {
type: "header" | "Daily Offerings" | "date";
date: Date;
prefix: string;
suffix: string;
};
menu: {
items: string[];
};
};
type Context = {
menuType: keyof typeof DOEMenuTypes;
dailyOfferings?: Line;
};
export async function calendarItemForLine(context: Context, line: Line) {
const menuType = DOEMenuTypes[context.menuType];
if (line.date.type == "date") {
const fullMenu = formatMenuLines(line.menu.items);
let descriptionLines: string[] = [
`*${line.date.suffix} Menu*`,
`${menuType.title} for ${line.date.prefix}`,
"\n",
...fullMenu,
];
if (context.dailyOfferings) {
const dailyOfferingItems = formatMenuLines(
context.dailyOfferings.menu.items,
);
if (dailyOfferingItems.length > 0) {
descriptionLines = [
...descriptionLines,
"\n*Daily Offerings*\n",
...dailyOfferingItems,
];
}
}
const description = descriptionLines.join("\n");
const start = new Date(line.date.date);
return ({
start,
allDay: true,
summary: `DoE Lunch`,
description,
});
}
}
October 23, 2023