Add language config to html() function

This commit is contained in:
Kuba Orlik 2024-03-14 13:01:09 +01:00
parent ba97321778
commit 4aa6fc7684
2 changed files with 7 additions and 1 deletions

View File

@ -15,3 +15,4 @@ export const MAILCATCHER_API_PORT = parseInt(
process.env.SEALIOUS_MAILCATCHER_API_PORT || "1082"
);
export const MAILER = process.env.SEALIOUS_MAILER;
export const DEFAULT_HTML_LANG = "pl";

View File

@ -3,6 +3,7 @@ import { Readable } from "stream";
import { BaseContext } from "koa";
import { default as default_navbar } from "./routes/common/navbar.js";
import { toKebabCase } from "js-convert-case";
import { DEFAULT_HTML_LANG } from "./config.js";
export const defaultHead = (
ctx: BaseContext,
@ -30,6 +31,7 @@ export type HTMLOptions = {
navbar?: (ctx: BaseContext) => FlatTemplatable;
autoRefreshCSS?: boolean;
disableCopyEvent?: boolean;
language?: string;
};
export default function html(
@ -45,7 +47,10 @@ export default function html(
): Readable {
ctx.set("content-type", "text/html;charset=utf-8");
return tempstream/* HTML */ ` <!DOCTYPE html>
<html lang="pl" class="title--${toKebabCase(title)}">
<html
lang="${htmlOptions.language || DEFAULT_HTML_LANG}"
class="title--${toKebabCase(title)}"
>
<head>
${makeHead(ctx, title, htmlOptions)}
</head>