chore: minify html

This commit is contained in:
Cory Dransfeldt 2024-11-08 05:26:31 -08:00
parent 554ce4dd01
commit 0114acdffb
No known key found for this signature in database
2 changed files with 9 additions and 2 deletions

View file

@ -1,5 +1,6 @@
import { createClient } from "@supabase/supabase-js"; import { createClient } from "@supabase/supabase-js";
import { fetchDataByUrl, fetchGlobals } from "./utils/fetchers.js"; import { fetchDataByUrl, fetchGlobals } from "./utils/fetchers.js";
import { minifyHTML } from "./utils/formatters.js";
import { import {
generateArtistHTML, generateArtistHTML,
generateBookHTML, generateBookHTML,
@ -67,7 +68,7 @@ export default {
const templateResponse = await fetch(`${BASE_URL}/dynamic`); const templateResponse = await fetch(`${BASE_URL}/dynamic`);
const template = await templateResponse.text(); const template = await templateResponse.text();
const metadata = generateMetadata(data, type, globals); const metadata = generateMetadata(data, type, globals);
const html = updateDynamicContent(template, metadata, mediaHtml); const html = minifyHTML(updateDynamicContent(template, metadata, mediaHtml));
const headers = new Headers({ const headers = new Headers({
"Content-Type": "text/html", "Content-Type": "text/html",
"Cache-Control": "Cache-Control":

View file

@ -17,4 +17,10 @@ md.use(markdownItAnchor, {
safariReaderFix: true, safariReaderFix: true,
}), }),
}); });
md.use(markdownItFootnote); md.use(markdownItFootnote);
export const minifyHTML = (html) =>
html
.replace(/\n\s+/g, "")
.replace(/>\s+</g, "><")
.replace(/<!--.*?-->/g, "");