shadowfacts.net/lib/layout.ts

23 lines
736 B
TypeScript
Raw Normal View History

2019-01-04 18:14:53 +00:00
import path from "path";
import * as metadata from "./metadata";
import { Metadata } from "./metadata";
import * as util from "./util";
2019-01-04 18:14:53 +00:00
2021-04-09 01:41:05 +00:00
// create the date once so that every page uses the same value
const stylesheetCacheBuster = new Date().getTime();
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);
2019-01-05 02:59:52 +00:00
text = util.render(layoutPage.text, {
2019-01-04 18:14:53 +00:00
content: text,
2021-04-09 01:41:05 +00:00
metadata: pageMetadata,
stylesheetCacheBuster,
2019-01-05 02:59:52 +00:00
}, layoutFile);
2019-01-04 18:14:53 +00:00
if (layoutPage.metadata.layout) {
return await layout(text, pageMetadata, layoutPage.metadata.layout);
} else {
return text;
}
2021-04-09 01:41:05 +00:00
}