diff --git a/lib/html_head.typ b/lib/html_head.typ index 04fa55f..1583535 100644 --- a/lib/html_head.typ +++ b/lib/html_head.typ @@ -1,5 +1,6 @@ #import "./custom_html.typ" as chtml #import "./html_utils.typ": get-css, get-js +#import "./pyscript.typ": state-use-pyscript, state-pyscript-headers, state-pyscript-version /// Generate the html element for the page. #let html_head( @@ -35,7 +36,8 @@ // The width=device-width part sets the width of the page to follow the screen-width of the device (which will vary depending on the device). // The initial-scale=1.0 part sets the initial zoom level when the page is first loaded by the browser. - html.meta(name: "viewport", content: "width=device-width, initial-scale=1.0") + // it resize the content instead of only resizeing the visual 'window'. (https://developer.chrome.com/blog/viewport-resize-behavior#:%7E:text=Through%20the%20interactive-widget%20key,Visual%20Viewport%20and%20Layout%20Viewport.) + html.meta(name: "viewport", content: "width=device-width, initial-scale=1.0, interactive-widget=resizes-content") // Only set the Referer header for out request to the same origin html.meta(name: "referrer", content: "same-origin") @@ -93,6 +95,18 @@ } }} + context if state-use-pyscript.final() { + assert( + state-pyscript-version.final() != none, + message: "Cannot run python script: pyscript-version is not set" + ) + assert( + state-pyscript-version.final() in state-pyscript-headers.final(), + message: "Cannot run python script: urls for " + state-pyscript-version.final() + " not set in pyscript-urls" + ) + state-pyscript-headers.final().at(state-pyscript-version.final()) + } + html.style(get-css()) html.script(get-js()) diff --git a/lib/main.typ b/lib/main.typ index 93cefae..30a728f 100644 --- a/lib/main.typ +++ b/lib/main.typ @@ -2,6 +2,7 @@ #import "./html_body.typ": html_body #import "./html_utils.typ": html_show #import "./summary.typ": summary, card-list +#import "./pyscript.typ": state-use-pyscript, state-pyscript-headers, state-pyscript-version, pyscript #import "./rss.typ": rss #import "./icons.typ" @@ -31,6 +32,10 @@ stylesheets: (), /// List of related sites for metadata me-links: (), + /// Dictionnary of available tags to add in header for each versions of pyscript + pyscript-headers: (:), + /// Pyscript version to use + pyscript-version: none, //-- Body -- /// Array of element to add on the top left of the page nav-elements: none, @@ -47,6 +52,10 @@ body ) = { assert(type(url) == str, message: "A page must have an url") + context { + state-pyscript-headers.update(x => pyscript-headers) + state-pyscript-version.update(x => pyscript-version) + } show: html_show html.html(lang: lang, { html_head( diff --git a/lib/pyscript.typ b/lib/pyscript.typ new file mode 100644 index 0000000..4c546e4 --- /dev/null +++ b/lib/pyscript.typ @@ -0,0 +1,16 @@ +#let state-use-pyscript = state("state-use-pyscript", false) +#let state-pyscript-version = state("state-pyscript-version", none) +#let state-pyscript-headers = state("state-pyscript-headers", (:)) + +#let pyscript(body) = { + show raw.where(block: true, lang: "python"): it => { + state-use-pyscript.update(x => true) + it + html.elem("script", attrs: ( + type: "py", + terminal: "", + worker: "", + ), it.text) + } + body +} diff --git a/test_template/main.typ b/test_template/main.typ index 4c71c42..cf28bab 100644 --- a/test_template/main.typ +++ b/test_template/main.typ @@ -59,11 +59,34 @@ ], site-name: "TTT", icon: "https://jean-marie.mineau.eu/website_assets/platypus.png", + + // Pyscript: + pyscript-headers: ( + "remote-2026.3.1": { + html.elem("script", attrs: (type: "module", src: "https://pyscript.net/releases/2026.3.1/core.js")) + html.elem("link", attrs: (rel: "stylesheet", href: "https://pyscript.net/releases/2026.3.1/core.js")) + } + ), + pyscript-version: "remote-2026.3.1", ) #lorem(400) +#pyscript[ + ```python + for i in range(1, 16): + if i % 3 == 0 and i % 5 == 0: + print("plopliplop") + elif i % 3 == 0: + print("plop") + elif i % 5 == 0: + print("plip") + else: + print(i) + ``` +] + #summ.card Test, `this is not a code block`, end test.