diff options
Diffstat (limited to 'book/book.js')
| -rw-r--r-- | book/book.js | 69 | 
1 files changed, 41 insertions, 28 deletions
| diff --git a/book/book.js b/book/book.js index 00c83426..2ae7335a 100644 --- a/book/book.js +++ b/book/book.js @@ -1,16 +1,15 @@  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 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", @@ -26,14 +25,24 @@ const emph = (t, th) => ({      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 = () => ({ +const toc = (pages) => ({      t: "page", background: "toc", es: [ -        { t: "text", s: plain("TODO: Table of contents"), size: 20, font: "FreeSans", color: "#000000" } +        h2("b.toc"), +        { +            t: "list", es: pages.map(p => ref(p.ref, ({ +                t: "container", es: [ +                    par(p.title), +                    { t: "align", dir: "flow_end", e: par_raw(plain(`${p.page}`)) } +                ] +            }))) +        },      ]  })  const about = () => ({ @@ -67,25 +76,29 @@ const recipe = (n, i, th = false, 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(), -        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() +        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))      ]  })) | 
