feat: add lang to <html> (#47)

This commit is contained in:
Luca Casonato
2021-08-06 18:36:04 +02:00
committed by GitHub
parent 0777c1c7ba
commit 384daf0e06
2 changed files with 13 additions and 1 deletions
+12 -1
View File
@@ -21,6 +21,7 @@ export class RenderContext {
#head: ComponentChild[] = [];
#url: URL;
#route: string;
#lang = "en";
constructor(id: string, url: URL, route: string) {
this.#id = id;
@@ -59,6 +60,14 @@ export class RenderContext {
get route(): string {
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;
@@ -133,6 +142,7 @@ export async function render(opts: RenderOptions): Promise<string> {
preloads: opts.preloads,
head: ctx.head,
props: templateProps,
lang: ctx.lang,
});
return html;
@@ -144,11 +154,12 @@ export interface TemplateOptions {
head: ComponentChild[];
preloads: string[];
props: unknown;
lang: string;
}
export function template(opts: TemplateOptions): string {
const page = (
<html>
<html lang={opts.lang}>
<head>
{opts.preloads.map((src) => <link rel="modulepreload" href={src} />)}
{opts.imports.map((src) => <script src={src} type="module"></script>)}