Skip to main content
Home

Built and signed on GitHub Actions

Works with
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
•JSR Score100%•
Downloads1/wk
•
Publisheda month ago (0.9.4)

🌊 Lightweight HTML templating library for any-side rendering

class Server

Server side renderer.

See mizu.sh documentation for more details.

Constructors

new
Server(options?: ServerOptions)

Server constructor.

Properties

writeonly
context: Record<PropertyKey, unknown>
readonly
context: Record<PropertyKey, any>

Default rendering context.

All properties assigned to this object are accessible during rendering.

Methods

Generate static files from various sources.

Options:

  • output: Specify the path to the output directory.
  • clean: Empty the output directory before generating files.

Supported sources:

  • StringSource: Generate content from raw strings.
  • GlobSource: Generate content from local files matching the provided glob patterns.
  • CallbackSource: Generate content from callback returns.
  • URLSource: Generate content from fetched URLs.

Each source can be templated using mizu rendering by passing a render option.

const mizu = new Server({ directives: ["@mizu/test"], generate: { output: "/fake/output" } })
await mizu.generate(
  [
    // Copy content from strings
    [ "<p>foo</p>", "string.html" ],
    [ "<p ~test.text='foo'></p>", "string_render.html", { render: { context: { foo: "bar" } } } ],
    // Copy content from local files
    [ "**\/*", "public", { directory: "/fake/static" } ],
    [ "*.html", "public", { directory: "/fake/partials", render: { context: { foo: "bar "} } } ],
    // Copy content from callback return
    [ () => JSON.stringify({ foo: "bar" }), "callback.json" ],
    [ () => `<p ~test.text="'foo'"></p>`, "callback.html", { render: { context: { foo: "bar" } } } ],
    // Copy content from URL
    [ new URL(`data:text/html,<p>foobar</p>`), "url.html" ],
    [ new URL(`data:text/html,<p ~test.text="foo"></p>`), "url_render.html", { render: { context: { foo: "bar" } } } ],
  ],
  // No-op: do not actually write files and directories
  { fs: { readdir: () => Promise.resolve([] as string[]), mkdir: () => null as any, write: () => null as any } },
)
render(
content: string | Arg<Renderer["render"]>,
options?: ServerRenderOptions & Pick<ServerOptions, "warn">,
): Promise<string>

Parse an HTML string and render all subtrees.

The *mizu attribute is only required if implicit is set to false.

const mizu = new Server({ context: { foo: "bar" } })
await mizu.render(`<html><body><a ~test.text="foo"></a></body></html>`)

Static Properties

readonly
default: Server

Default Server instance.

Default options for Server.

These default options are merged with the provided options when creating a new Server instance.

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@mizu/render

Import symbol

import { Server } from "@mizu/render/server";
or

Import directly with a jsr specifier

import { Server } from "jsr:@mizu/render/server";

Add Package

pnpm i jsr:@mizu/render
or (using pnpm 10.8 or older)
pnpm dlx jsr add @mizu/render

Import symbol

import { Server } from "@mizu/render/server";

Add Package

yarn add jsr:@mizu/render
or (using Yarn 4.8 or older)
yarn dlx jsr add @mizu/render

Import symbol

import { Server } from "@mizu/render/server";

Add Package

vlt install jsr:@mizu/render

Import symbol

import { Server } from "@mizu/render/server";

Add Package

npx jsr add @mizu/render

Import symbol

import { Server } from "@mizu/render/server";

Add Package

bunx jsr add @mizu/render

Import symbol

import { Server } from "@mizu/render/server";