This commit is contained in:
2026-03-19 14:27:41 -05:00
parent 507caba410
commit 7641641ccd
4 changed files with 32 additions and 4 deletions

9
src/locale.ts Normal file
View File

@@ -0,0 +1,9 @@
export const LANGUAGES = <const>{
'en': 'English'
};
export type LocaleLanguage = keyof typeof LANGUAGES;
export type LocaleString = {
[K in LocaleLanguage]:string;
};

View File

@@ -2,9 +2,10 @@ import { Request, Response } from 'express';
import { SectionData, sectionRender } from "./section"; import { SectionData, sectionRender } from "./section";
import TemplateDefault from "./templates/default"; import TemplateDefault from "./templates/default";
import { templateRender } from './template'; import { templateRender } from './template';
import { LocaleString } from './locale';
export type Page = { export type Page = {
title?:string; title?:LocaleString;
sections:SectionData<any>[]; sections:SectionData<any>[];
} }

View File

@@ -3,12 +3,17 @@ import { Page } from "./page";
export type Template = { export type Template = {
name:string; name:string;
render:(p:{
page:Page;
request:Request;
language:Language;
}) => Promise<string>;
} }
export const templateRender = async (p:{ export const templateRender = (p:{
page:Page, page:Page,
template:Template, template:Template,
request:Request request:Request
}):Promise<string> => { }):Promise<string> => {
return 'template'; return p.template.render(p);
} }

View File

@@ -1,7 +1,20 @@
import { Template } from "../template"; import { Template } from "../template";
const TEMPLATE_DEFAULT:Template = { const TEMPLATE_DEFAULT:Template = {
name: 'default' name: 'default',
render: async p => {
return [
`<!DOCTYPE html>`,
`<html>`,
`<head>`,
`<title>${p.page.title[language] || 'Untitled Page'}</title>`,
`</head>`,
`<body>`,
`body`,
`</body>`,
`</html>`
].join('\n');
}
}; };
export default TEMPLATE_DEFAULT; export default TEMPLATE_DEFAULT;