forked from shadowfacts/shadowfacts.net
24 lines
718 B
TypeScript
24 lines
718 B
TypeScript
import path from "path";
|
|
import ejs from "ejs";
|
|
import formatDate from "date-fns/format";
|
|
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 = ejs.render(layoutPage.text, {
|
|
content: text,
|
|
metadata: pageMetadata,
|
|
formatDate,
|
|
fancyLink: util.fancyLink
|
|
}, {
|
|
filename: layoutFile,
|
|
});
|
|
if (layoutPage.metadata.layout) {
|
|
return await layout(text, pageMetadata, layoutPage.metadata.layout);
|
|
} else {
|
|
return text;
|
|
}
|
|
} |