aboutsummaryrefslogtreecommitdiffstats
path: root/app/builder/render.ts
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.com>2023-08-28 21:54:57 +0100
committerLeonardo Bishop <me@leonardobishop.com>2023-08-28 21:54:57 +0100
commit7c8ca1c5cf0067a350578d5589139abf076ef1ec (patch)
treec3dfb0aa397c684dae64039524c99d28b4cec369 /app/builder/render.ts
parentb31733593683374366058a23a0a470911e2722c0 (diff)
Add html minification
Diffstat (limited to 'app/builder/render.ts')
-rw-r--r--app/builder/render.ts13
1 files changed, 12 insertions, 1 deletions
diff --git a/app/builder/render.ts b/app/builder/render.ts
index ed59cc6..5c1c125 100644
--- a/app/builder/render.ts
+++ b/app/builder/render.ts
@@ -2,6 +2,7 @@ import { Page, PageDirectory } from "./pages";
import ejs from 'ejs';
import path from 'path';
import buildInfo from "../config/info.js";
+import htmlMinify from 'html-minifier-terser';
export async function render(page: Page, pageDirectory: PageDirectory): Promise<string> {
const options = {
@@ -11,5 +12,15 @@ export async function render(page: Page, pageDirectory: PageDirectory): Promise<
},
build: buildInfo,
};
- return await ejs.renderFile(path.join(process.env.VIEWS_DIR, `${page.view}.ejs`), options);
+ const html = await ejs.renderFile(path.join(process.env.VIEWS_DIR, `${page.view}.ejs`), options);
+
+ const minifiedHtml = await htmlMinify.minify(html, {
+ collapseWhitespace: true,
+ removeComments: true,
+ continueOnParseError: true,
+ minifyCSS: true,
+ minifyJS: true,
+ });
+
+ return minifiedHtml;
}