test
This commit is contained in:
9
src/locale.ts
Normal file
9
src/locale.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
export const LANGUAGES = <const>{
|
||||||
|
'en': 'English'
|
||||||
|
};
|
||||||
|
|
||||||
|
export type LocaleLanguage = keyof typeof LANGUAGES;
|
||||||
|
|
||||||
|
export type LocaleString = {
|
||||||
|
[K in LocaleLanguage]:string;
|
||||||
|
};
|
||||||
@@ -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>[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
Reference in New Issue
Block a user