aboutsummaryrefslogtreecommitdiff
path: root/book/book.js
blob: 8242284198e7506c3b53607ea7b8409f4cfb1d48 (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const tr = t => ({ translation: { id: t, params: [] } })
const plain = t => ({ text: t })
const span_raw = (s, th, bold) => ({
    t: "text",
    s,
    color: th ? "#ffffff" : "#000000",
    size: 15,
    bold,
    font: "FreeSans"
})
const par_raw = (s, th, bold) => ({ t: "par", es: [span_raw(s, th, bold)] })
const par = (t, th, bold) => par_raw(tr(t), th, bold)
const h2 = (t, th) => ({
    t: "text",
    s: tr(t),
    color: th ? "#ffffff" : "#000000",
    size: 40,
    font: "Great Vibes"
})
const emph = (t, th) => ({
    t: "text",
    s: tr(t),
    color: th ? "#95bd51" : "#2e4900",
    size: 20,
    font: "Gluten"
})
const label = (id, e) => ({ t: "label", id, e })
const ref = (id, e) => ({ t: "ref", id, e })
const title = () => ({
    t: "page", background: "cover", es: [
        { t: "text", s: tr("b.title"), size: 70, color: "#000000", font: "Great Vibes" }
    ]
})
const toc = (pages) => ({
    t: "page", background: "toc", es: [
        h2("b.toc"),
        {
            t: "list", es: pages.map(p => ref(p.ref, ({
                t: "par", es: [
                    span_raw(tr(p.title)),
                    { t: "align", dir: "flow_end", e: par_raw(plain(`${p.page}`)) }
                ]
            })))
        },
    ]
})
const about = () => ({
    t: "page", es: [
        { t: "text", s: tr("b.about"), color: "#000000", size: 30, font: "FreeSans" },
        par("b.about.name"),
        { t: "conditional", cond: "image_attribution", value: true, e: { t: "text", s: tr("b.about.image_attrib"), color: "#000000", size: 20, font: "FreeSans" } },
        {
            t: "conditional", cond: "image_attribution", value: true, e:
            {
                t: "table", es: [
                    [par("b.about.image_attrib.name", false, true), par("b.about.image_attrib.author", false, true)],
                    [par("b.nigiri"), par_raw(plain("Ahtziri Lagarde (unsplash)"))],
                    [par("b.icecream"), par_raw(plain("Markus Spiske (unsplash), adapted"))],
                    [par("b.curry"), par_raw(plain("Andy Hay (unsplash), adapted"))],
                    [par("b.mochi"), par_raw(plain("blackieshoot (unsplash)"))],
                    [par("b.burger"), par_raw(plain("Pablo Merchán Montes (unsplash), adapted"))],
                    [par("b.tomato_soup"), par_raw(plain("Julia Kicova (unsplash), adapted"))],
                ]
            }
        }
    ]
})
const recipe = (n, i, th = false, extra = []) => ({
    t: "page", background: n, es: [
        h2(`b.${n}`, th),
        par(`b.${n}.desc`, th),
        { t: "list", es: i.map(e => emph(`b.ingred.${e}`, th)) },
        par(`b.${n}.steps`, th),
        ...extra
    ]
})

const toc_pages = [
    recipe("tomato_soup", ["leek", "tomato"]),
    recipe("bun", ["flour"], true),
    recipe("burger", ["lettuce", "tomato", "cheese", "steak", "bun"], true, [par("b.burger.variation", true)]),
    recipe("mochi", ["rice", "strawberry"], true),
    recipe("curry", ["coconut", "tomato", "leek", "rice"], true),
    recipe("icecream", ["strawberry", "coconut"]),
    recipe("nigiri", ["fish", "rice"]),
    {
        t: "page", background: "drinks", es: [
            { t: "text", s: tr(`b.water`), color: "#ffffff", size: 30, font: "Great Vibes" },
            par("b.water.steps", true),
            { t: "text", s: tr(`b.strawberry_shake`), color: "#ffffff", size: 30, font: "Great Vibes" },
            par("b.strawberry_shake.steps", true),
        ]
    },
    about()
]

console.log(JSON.stringify({
    t: "document", es: [
        title(),
        toc(toc_pages.map((p, i) => ({ page: i + 3, title: p.es[0].s.translation.id, ref: `page.${i}` }))),
        ...toc_pages.map((p, i) => label(`page.${i}`, p))
    ]
}))