feat: add lang to <html> (#47)
This commit is contained in:
+12
-1
@@ -21,6 +21,7 @@ export class RenderContext {
|
|||||||
#head: ComponentChild[] = [];
|
#head: ComponentChild[] = [];
|
||||||
#url: URL;
|
#url: URL;
|
||||||
#route: string;
|
#route: string;
|
||||||
|
#lang = "en";
|
||||||
|
|
||||||
constructor(id: string, url: URL, route: string) {
|
constructor(id: string, url: URL, route: string) {
|
||||||
this.#id = id;
|
this.#id = id;
|
||||||
@@ -59,6 +60,14 @@ export class RenderContext {
|
|||||||
get route(): string {
|
get route(): string {
|
||||||
return this.#route;
|
return this.#route;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The language of the page being rendered. Defaults to "en". */
|
||||||
|
get lang(): string {
|
||||||
|
return this.#lang;
|
||||||
|
}
|
||||||
|
set lang(lang: string) {
|
||||||
|
this.#lang = lang;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAX_SUSPENSE_DEPTH = 10;
|
const MAX_SUSPENSE_DEPTH = 10;
|
||||||
@@ -133,6 +142,7 @@ export async function render(opts: RenderOptions): Promise<string> {
|
|||||||
preloads: opts.preloads,
|
preloads: opts.preloads,
|
||||||
head: ctx.head,
|
head: ctx.head,
|
||||||
props: templateProps,
|
props: templateProps,
|
||||||
|
lang: ctx.lang,
|
||||||
});
|
});
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
@@ -144,11 +154,12 @@ export interface TemplateOptions {
|
|||||||
head: ComponentChild[];
|
head: ComponentChild[];
|
||||||
preloads: string[];
|
preloads: string[];
|
||||||
props: unknown;
|
props: unknown;
|
||||||
|
lang: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function template(opts: TemplateOptions): string {
|
export function template(opts: TemplateOptions): string {
|
||||||
const page = (
|
const page = (
|
||||||
<html>
|
<html lang={opts.lang}>
|
||||||
<head>
|
<head>
|
||||||
{opts.preloads.map((src) => <link rel="modulepreload" href={src} />)}
|
{opts.preloads.map((src) => <link rel="modulepreload" href={src} />)}
|
||||||
{opts.imports.map((src) => <script src={src} type="module"></script>)}
|
{opts.imports.map((src) => <script src={src} type="module"></script>)}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ Deno.test("/ page prerender", async () => {
|
|||||||
assertEquals(resp.status, 200);
|
assertEquals(resp.status, 200);
|
||||||
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
|
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
|
||||||
const body = await resp.text();
|
const body = await resp.text();
|
||||||
|
assertStringIncludes(body, `<html lang="en">`);
|
||||||
assertStringIncludes(body, "index.js");
|
assertStringIncludes(body, "index.js");
|
||||||
assertStringIncludes(body, "<p>Hello!</p>");
|
assertStringIncludes(body, "<p>Hello!</p>");
|
||||||
assertStringIncludes(body, "<p>Viewing JIT render.</p>");
|
assertStringIncludes(body, "<p>Viewing JIT render.</p>");
|
||||||
|
|||||||
Reference in New Issue
Block a user