From d97a5f36ea4fb6111d1dea3ffcbacebe46fe197e Mon Sep 17 00:00:00 2001 From: Atridad Lahiji Date: Sat, 10 Jan 2026 02:03:24 -0700 Subject: [PATCH] pls --- docs/astro.config.mjs | 4 ++++ docs/src/middleware.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 docs/src/middleware.ts diff --git a/docs/astro.config.mjs b/docs/astro.config.mjs index 2ae1f69..4396611 100644 --- a/docs/astro.config.mjs +++ b/docs/astro.config.mjs @@ -55,4 +55,8 @@ export default defineConfig({ adapter: node({ mode: "standalone", }), + + build: { + inlineStylesheets: "always", + }, }); diff --git a/docs/src/middleware.ts b/docs/src/middleware.ts new file mode 100644 index 0000000..573515e --- /dev/null +++ b/docs/src/middleware.ts @@ -0,0 +1,31 @@ +import { defineMiddleware } from "astro:middleware"; + +export const onRequest = defineMiddleware(async (_, next) => { + const response = await next(); + + const contentType = response.headers.get("Content-Type") || ""; + + // Only modify HTML responses + if (contentType.includes("text/html")) { + const html = await response.text(); + + // Optimize LCP image by setting fetchpriority="high" on the hero image + // Target specific image by its alt text seen in PageSpeed Insights + const optimizedHtml = html.replace( + /]*?)alt="Ascently app icon"([^>]*?)>/, + (match, p1, p2) => { + if (match.includes("fetchpriority=")) { + return match.replace(/fetchpriority="[^"]*"/, 'fetchpriority="high"'); + } + return ``; + } + ); + + return new Response(optimizedHtml, { + status: response.status, + headers: response.headers, + }); + } + + return response; +});