112 lines
2.6 KiB
Typst
112 lines
2.6 KiB
Typst
#import "@local/template-web:0.0.1": *
|
|
#import "/lib.typ": webpage
|
|
|
|
#let summ = summary(
|
|
base-url: "http://test.example.com",
|
|
path: "/pycript.html",
|
|
title: "TeTyTe",
|
|
page-label: <pyscript-label>,
|
|
preview-image: 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.",
|
|
),
|
|
author: "Me!",
|
|
tags: ("test", "html/css", "typst", "pyscript"),
|
|
description: "Demonstrate how to use pyscript to run python in the browser",
|
|
date: datetime(year: 1942, month: 4, day: 1),
|
|
)
|
|
|
|
#show: webpage.with(
|
|
..summ.template-args,
|
|
header: [
|
|
= Showcase Pyscript
|
|
Show how to run Python in the browser
|
|
],
|
|
// 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 <mini-coi> 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",
|
|
)
|
|
|
|
```python-run
|
|
n = ""
|
|
while not n.isnumeric():
|
|
n = input("enter a valid number: ")
|
|
|
|
for i in range(1, int(n) + 1):
|
|
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)
|
|
```
|
|
```python-run
|
|
# /// script
|
|
# # requires-python = ">=3.11" # not supported yet
|
|
# dependencies = [
|
|
# "rich",
|
|
# ]
|
|
#
|
|
# [tool.pyscript]
|
|
# repl = true
|
|
# [tool.pyscript.files]
|
|
# "https://peps.python.org/api/peps.json" = "./peps.json"
|
|
# ///
|
|
|
|
import json
|
|
from rich.pretty import pprint
|
|
|
|
with open("./peps.json") as fd:
|
|
data = json.load(fd)
|
|
pprint([(k, v["title"]) for k, v in data.items()][:10])
|
|
# >>> print(data["723"]["title"])
|
|
# Inline script metadata
|
|
```
|
|
|
|
```python-run
|
|
# /// script
|
|
# # requires-python = ">=3.11" # not supported yet
|
|
# dependencies = [
|
|
# "rich",
|
|
# ]
|
|
#
|
|
# [tool.pyscript]
|
|
# repl = true
|
|
# hide-meta = true
|
|
# [tool.pyscript.files]
|
|
# "https://peps.python.org/api/peps.json" = "./peps.json"
|
|
# ///
|
|
# setting tool.pyscript.hide-meta to true will hide the `/// script` section
|
|
import json
|
|
from rich.pretty import pprint
|
|
|
|
with open("./peps.json") as fd:
|
|
data = json.load(fd)
|
|
pprint([(k, v["title"]) for k, v in data.items()][:10])
|
|
# >>> print(data["723"]["title"])
|
|
# Inline script metadata
|
|
```
|
|
|
|
```python-run
|
|
# /// script
|
|
# dependencies = [
|
|
# "pygame-ce",
|
|
# "./python-packages/isn_s_cube-0.1.0-py3-none-any.whl"
|
|
# ]
|
|
# [tool.pyscript]
|
|
# pygame = true
|
|
# ///
|
|
from isn_s_cube import wasm
|
|
await wasm()
|
|
```
|
|
|