From 500a6ad1814a3963ad788b2e80e1f3e67144f42c Mon Sep 17 00:00:00 2001 From: Jean-Marie 'Histausse' Mineau Date: Wed, 17 Jun 2026 22:12:31 +0200 Subject: [PATCH] curry the example webpage() function in a common lib.typ --- lib/states.typ | 10 +++++++-- test_template/lib.typ | 35 ++++++++++++++++++++++++++++++++ test_template/pages/cards.typ | 31 +--------------------------- test_template/pages/index.typ | 32 +---------------------------- test_template/pages/pyscript.typ | 19 +---------------- 5 files changed, 46 insertions(+), 81 deletions(-) create mode 100644 test_template/lib.typ diff --git a/lib/states.typ b/lib/states.typ index f9e7e99..eefb695 100644 --- a/lib/states.typ +++ b/lib/states.typ @@ -39,12 +39,18 @@ /// Concatenate all css found in css-list at the end of the document #let get-css(page-label) = context { - html.style(css-list.at(label(str(page-label) + "-end")).join("\n\n")) + let end-page-label = label(str(page-label) + "-end") + if css-list.at(end-page-label) != () { + html.style(css-list.at(end-page-label).join("\n\n")) + } else {} } /// Concatenate all js found in js-list at the end of the document #let get-js(page-label) = context { - html.script(js-list.at(label(str(page-label) + "-end")).join("\n\n")) + let end-page-label = label(str(page-label) + "-end") + if js-list.at(end-page-label) != () { + html.script(js-list.at(end-page-label).join("\n\n")) + } else {} } #let reset-page-states() = { diff --git a/test_template/lib.typ b/test_template/lib.typ new file mode 100644 index 0000000..609cfdd --- /dev/null +++ b/test_template/lib.typ @@ -0,0 +1,35 @@ +#import "@local/template-web:0.0.1": webpage as webpage-org, icons + +#let webpage = webpage-org.with( + logo: image( + "/assets/platypus.png", + alt: "A drawing of a blue-ish round-ish platypus with big eyes, holding a laptop. This platypus is quite cute, but I might be biased.", + height: 100pt, + width: 100pt, // TODO 0.15 regression? in 0.14 setting the height was enough + ), + footer: context [ + + #sym.copyright #document.date.display("[year]") Histausse \ + Please don't train AI on my stuff without explicit permission + ], + nav-elements: ( + /* + link( + "http://test.example.com", + image( + "/assets/platypus.png", + alt: "A drawing of a blue-ish round-ish platypus with big eyes, holding a laptop. This platypus is quite cute, but I might be biased.", + height: 2em, + ) + ),*/ + html.a(href: "http://test.example.com", aria-label: "Home", icons.home-icon), // /!\ aria-label is important for accessibility /!\ + html.a(href: "/feed.rss", aria-label: "RSS feed", icons.rss-icon), + ), + menu: [ + - #link()[Home] + - #link()[Demo Pyscript] + - #link()[Demo the summary card system] + ], + site-name: "TTT", + icon: "/img/platypus.png", // TODO: use somehow? probably not supported in 0.15 +) diff --git a/test_template/pages/cards.typ b/test_template/pages/cards.typ index 4371dda..efbbe60 100644 --- a/test_template/pages/cards.typ +++ b/test_template/pages/cards.typ @@ -1,4 +1,5 @@ #import "@local/template-web:0.0.1": * +#import "/lib.typ": webpage #let summ = summary( base-url: "http://test.example.com", @@ -17,40 +18,10 @@ #show: webpage.with( ..summ.template-args, - logo: image( - "/assets/platypus.png", - alt: "A drawing of a blue-ish round-ish platypus with big eyes, holding a laptop. This platypus is quite cute, but I might be biased.", - height: 100pt, - width: 100pt, // TODO 0.15 regression? in 0.14 setting the height was enough - ), header: [ = Summary Cards Showcase summary cards ], - footer: context [ - - #sym.copyright #document.date.display("[year]") Histausse \ - Please don't train AI on my stuff without explicit permission - ], - menu: [ - - #link()[Home] - - #link()[Demo Pyscript] - - #link()[Demo the card system] - ], - site-name: "TTT", - icon: "/img/platypus.png", // TODO: use somehow? probably not supported in 0.15 - - // Pyscript: - pyscript-data-list: ( - "remote-2026.3.1": pyscript-data( - "https://pyscript.net/releases/2026.3.1/core.js", - additionnal-head-tags: { - html.elem("script", attrs: (src: "/mini-coi.js")) // TODO: use somehow? probably not supported in 0.15 - html.elem("link", attrs: (rel: "stylesheet", href: "https://pyscript.net/releases/2026.3.1/core.css")) - }, - ) - ), - pyscript-version: "remote-2026.3.1", ) diff --git a/test_template/pages/index.typ b/test_template/pages/index.typ index a915368..15fd18d 100644 --- a/test_template/pages/index.typ +++ b/test_template/pages/index.typ @@ -1,4 +1,5 @@ #import "@local/template-web:0.0.1": * +#import "/lib.typ": webpage #let summ = summary( base-url: "http://test.example.com", @@ -17,41 +18,10 @@ #show: webpage.with( ..summ.template-args, - logo: image( - "/assets/platypus.png", - alt: "A drawing of a blue-ish round-ish platypus with big eyes, holding a laptop. This platypus is quite cute, but I might be biased.", - height: 100pt, - width: 100pt, // TODO 0.15 regression? in 0.14 setting the height was enough - ), header: [ = Test TeTyTe Hello World! ], - footer: context [ - - #sym.copyright #document.date.display("[year]") Histausse \ - Please don't train AI on my stuff without explicit permission - ], - nav-elements: ( - /* - link( - "http://test.example.com", - image( - "/assets/platypus.png", - alt: "A drawing of a blue-ish round-ish platypus with big eyes, holding a laptop. This platypus is quite cute, but I might be biased.", - height: 2em, - ) - ),*/ - html.a(href: "http://test.example.com", aria-label: "Home", icons.home-icon), // /!\ aria-label is important for accessibility /!\ - html.a(href: "/feed.rss", aria-label: "RSS feed", icons.rss-icon), - ), - menu: [ - - #link()[Home] - - #link()[Demo Pyscript] - - #link()[Demo the summary card system] - ], - site-name: "TTT", - icon: "/img/platypus.png", // TODO: use somehow? probably not supported in 0.15 ) diff --git a/test_template/pages/pyscript.typ b/test_template/pages/pyscript.typ index 28b0c7e..d46f40e 100644 --- a/test_template/pages/pyscript.typ +++ b/test_template/pages/pyscript.typ @@ -1,4 +1,5 @@ #import "@local/template-web:0.0.1": * +#import "/lib.typ": webpage #let summ = summary( base-url: "http://test.example.com", @@ -17,28 +18,10 @@ #show: webpage.with( ..summ.template-args, - logo: image( - "/assets/platypus.png", - alt: "A drawing of a blue-ish round-ish platypus with big eyes, holding a laptop. This platypus is quite cute, but I might be biased.", - height: 100pt, - width: 100pt, // TODO 0.15 regression? in 0.14 setting the height was enough - ), header: [ = Showcase Pyscript Show how to run Python in the browser ], - footer: context [ - - #sym.copyright #document.date.display("[year]") Histausse \ - Please don't train AI on my stuff without explicit permission - ], - site-name: "TTT", - icon: "/img/platypus.png", // TODO: use somehow? probably not supported in 0.15 - menu: [ - - #link()[Home] - - #link()[Demo Pyscript] - - #link()[Demo the summary card system] - ], // Pyscript: pyscript-data-list: ( "remote-2026.3.1": pyscript-data(