2019-01-04 18:14:53 +00:00
|
|
|
import path from "path";
|
|
|
|
import ejs from "ejs";
|
|
|
|
import formatDate from "date-fns/format";
|
|
|
|
import * as metadata from "./metadata";
|
|
|
|
import { Metadata } from "./metadata";
|
2019-01-05 02:44:55 +00:00
|
|
|
import * as util from "./util";
|
2019-01-04 18:14:53 +00:00
|
|
|
|
|
|
|
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,
|
2019-01-05 02:44:55 +00:00
|
|
|
formatDate,
|
|
|
|
fancyLink: util.fancyLink
|
2019-01-04 18:14:53 +00:00
|
|
|
}, {
|
|
|
|
filename: layoutFile,
|
|
|
|
});
|
|
|
|
if (layoutPage.metadata.layout) {
|
|
|
|
return await layout(text, pageMetadata, layoutPage.metadata.layout);
|
|
|
|
} else {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
}
|