December 20, 2024
Lightweight HTML templating library for any-side rendering
#!/usr/bin/env -S deno serve --allow-read --allow-env
import Mizu from "@mizu/render/server"
export default {
async fetch() {
const headers = new Headers({ "Content-Type": "text/html; charset=utf-8" })
const body = await Mizu.render(``, { context: { foo: "🌊 Yaa, mizu!" } })
return new Response(body, { headers })
},
}
#!/usr/bin/env -S deno run --allow-read --allow-env --allow-net --allow-write=/tmp/output
import Mizu from "@mizu/render/server"
await Mizu.generate([
[``, "index.html", { render: { context: { foo: "🌊 Yaa, mizu!" } } }],
[() => JSON.stringify(Date.now()), "timestamp.json"],
["**/*", "static", { directory: "/fake/path" }],
[new URL("https://matcha.mizu.sh/matcha.css"), "styles.css"],
], { clean: true, output: "/tmp/output" })
1
2
3
4
5
6
7
8
9
10
11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import Mizu from "@mizu/render/server"
import { createServer } from "node:http"
createServer(async (_, response) => {
response.writeHead(200, { "Content-Type": "text/html; charset=utf-8" })
response.end(await Mizu.render(``, { context: { foo: "🌊 Yaa, mizu!" } }))
}).listen(8000, "0.0.0.0", () => console.log("Server is listening"))
import Mizu from "@mizu/render/server"
await Mizu.generate([
[``, "index.html", { render: { context: { foo: "🌊 Yaa, mizu!" } } }],
[() => JSON.stringify(Date.now()), "timestamp.json"],
["**/*", "static", { directory: "/fake/path" }],
[new URL("https://matcha.mizu.sh/matcha.css"), "styles.css"],
], { clean: true, output: "/tmp/output" })
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
9
10
11
12
13
import Mizu from "@mizu/render/server"
Bun.serve({
port: 8000,
async fetch() {
const headers = new Headers({ "Content-Type": "text/html; charset=utf-8" })
const body = await Mizu.render(``, { context: { foo: "🌊 Yaa, mizu!" } })
return new Response(body, { headers })
},
})
console.log("Server is listening")
import Mizu from "@mizu/render/server"
await Mizu.generate([
[``, "index.html", { render: { context: { foo: "🌊 Yaa, mizu!" } } }],
[() => JSON.stringify(Date.now()), "timestamp.json"],
["**/*", "static", { directory: "/fake/path" }],
[new URL("https://matcha.mizu.sh/matcha.css"), "styles.css"],
], { clean: true, output: "/tmp/output" })
1
2
3
4
5
6
7
8
9
10
11
12
13
1
2
3
4
5
6
7
8
9
10
11
12
13
2024-12-19 18:25:55