shadowfacts.net/lib/layout.ts

18 lines
593 B
TypeScript

import path from "path";
import * as metadata from "./metadata";
import { Metadata } from "./metadata";
import * as util from "./util";
export default async function layout(text: string, pageMetadata: Metadata, layoutPath: string): Promise<string> {
const layoutFile = path.join("site/layouts", layoutPath);
let layoutPage = await metadata.get(layoutFile);
text = util.render(layoutPage.text, {
content: text,
metadata: pageMetadata
}, layoutFile);
if (layoutPage.metadata.layout) {
return await layout(text, pageMetadata, layoutPage.metadata.layout);
} else {
return text;
}
}