summaryrefslogtreecommitdiff
path: root/book/book.js
blob: 00c8342649f27edef4a37754ec3abd029375b15d (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
const tr = t => ({ translation: { id: t, params: [] } })
const plain = t => ({ text: t })
const par_raw = (s, th, bold) => ({
    t: "par", es: [{
        t: "text",
        s,
        color: th ? "#ffffff" : "#000000",
        size: 15,
        bold,
        font: "FreeSans"
    }]
})
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 title = () => ({
    t: "page", background: "cover", es: [
        { t: "text", s: tr("b.title"), size: 70, color: "#000000", font: "Great Vibes" }
    ]
})
const toc = () => ({
    t: "page", background: "toc", es: [
        { t: "text", s: plain("TODO: Table of contents"), size: 20, font: "FreeSans", color: "#000000" }
    ]
})
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
    ]
})

console.log(JSON.stringify({
    t: "document", es: [
        title(),
        toc(),
        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()
    ]
}))