Only server-side render non-auth systems

pull/674/head
Zef Hemel 2024-01-28 19:24:59 +01:00
parent e2aa869660
commit dbabba7326
1 changed files with 14 additions and 11 deletions

View File

@ -113,20 +113,23 @@ export class HttpServer {
// Replaces some template variables in index.html in a rather ad-hoc manner, but YOLO
async renderHtmlPage(spaceServer: SpaceServer, pageName: string) {
console.log("Server side rendering", pageName);
let html = "";
try {
const { data } = await spaceServer.spacePrimitives.readFile(
`${pageName}.md`,
);
const text = new TextDecoder().decode(data);
const tree = parse(extendedMarkdownLanguage, text);
html = renderMarkdownToHtml(tree);
} catch (e: any) {
if (e.message !== "Not found") {
console.error("Error server-side rendering page", e);
if (!spaceServer.auth) {
// Only attempt server-side rendering when this site is not protected by auth
try {
const { data } = await spaceServer.spacePrimitives.readFile(
`${pageName}.md`,
);
const text = new TextDecoder().decode(data);
const tree = parse(extendedMarkdownLanguage, text);
html = renderMarkdownToHtml(tree);
} catch (e: any) {
if (e.message !== "Not found") {
console.error("Error server-side rendering page", e);
}
}
}
// TODO: Replace this with a proper template engine
return this.clientAssetBundle.readTextFileSync(".client/index.html")
.replace(
"{{SPACE_PATH}}",