A music player that connects to your cloud/distributed storage.
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: inline <-> compression inconsistency

+32 -70
+32 -70
_config.ts
··· 23 23 src: "./src", 24 24 server: { 25 25 debugBar: false, 26 - middlewares: [facetHtmlMiddleware], 26 + middlewares: [], 27 27 }, 28 28 }); 29 29 ··· 284 284 285 285 site.add("architecture.txt"); 286 286 287 - site.use(brotli()); 288 - site.use(sourceMaps()); 289 - 290 287 site.script("copy-type-defs", () => { 291 288 for ( 292 289 const f of walkSync( ··· 306 303 }); 307 304 308 305 //////////////////////////////////////////// 309 - // MIDDLEWARE 306 + // FILE TREE 310 307 //////////////////////////////////////////// 311 308 312 - // Facet HTML files are HTML fragments fetched via JS, not full pages. 313 - // Serving them as text/plain prevents Lume's dev server from injecting 314 - // its live-reload <script> tag into the fetched content. 315 - // 316 - // Also inlines any <script type="module" src="./foo.inline.js"> references so 317 - // that forked facets contain readable JS rather than an external file reference. 318 - async function facetHtmlMiddleware( 319 - request: Request, 320 - next: RequestHandler, 321 - ): Promise<Response> { 322 - const { pathname } = new URL(request.url); 323 - const isFacetHtml = pathname.endsWith(".html") && 324 - !pathname.startsWith("/testing/"); 325 - const response = await next(request); 326 - 327 - if (!isFacetHtml || !response.headers.get("content-type")?.includes("html")) { 328 - return response; 329 - } 330 - 331 - let content = await response.text(); 332 - content = await inlineScriptSrc(content); 333 - 334 - const headers = new Headers(response.headers); 335 - headers.set("content-type", "text/plain; charset=utf-8"); 336 - return new Response(content, { 337 - status: response.status, 338 - statusText: response.statusText, 339 - headers, 340 - }); 341 - } 342 - 343 - const SCRIPT_SRC_RE = 344 - /<script type="module" src="([^"]+\.inline\.js)"><\/script>/; 345 - 346 - async function inlineScriptSrc(content: string): Promise<string> { 347 - const match = SCRIPT_SRC_RE.exec(content); 348 - if (!match) return content; 349 - 350 - const jsPath = path.join("src", match[1]); 351 - try { 352 - return htmlWithInlineJs({ content, jsPath, match: match[0] }); 353 - } catch { 354 - return content; 355 - } 356 - } 357 - 358 - site.addEventListener("afterBuild", async () => { 359 - for ( 360 - const f of walkSync("./dist/", { includeDirs: false, exts: [".html"] }) 361 - ) { 362 - const content = Deno.readTextFileSync(f.path); 363 - const match = SCRIPT_SRC_RE.exec(content); 364 - if (!match) continue; 365 - 366 - const jsPath = path.join("src", match[1]); 367 - 368 - try { 369 - const newContent = htmlWithInlineJs({ content, jsPath, match: match[0] }); 370 - Deno.writeTextFileSync(f.path, newContent); 371 - } catch { 372 - // leave as-is if the source file can't be read 373 - } 374 - } 375 - }); 376 - 377 309 site.addEventListener("afterBuild", async () => { 378 310 const RAW = 0x55; 379 311 ··· 408 340 ); 409 341 }); 410 342 343 + //////////////////////////////////////////// 344 + // INLINE JS FOR FACETS 345 + //////////////////////////////////////////// 346 + 347 + const SCRIPT_SRC_RE = 348 + /<script type="module" src="([^"]+\.inline\.js)"><\/script>/; 349 + 350 + site.process([".html"], (pages) => { 351 + for (const page of pages) { 352 + const content = page.text; 353 + if (!content) continue; 354 + const match = SCRIPT_SRC_RE.exec(content); 355 + if (!match) continue; 356 + 357 + const jsPath = path.join("src", match[1]); 358 + try { 359 + page.text = htmlWithInlineJs({ content, jsPath, match: match[0] }); 360 + } catch { 361 + // leave as-is if the source file can't be read 362 + } 363 + } 364 + }); 365 + 411 366 function htmlWithInlineJs({ content, match, jsPath }: { 412 367 content: string; 413 368 match: string; ··· 419 374 ).trimEnd() + "\n"; 420 375 return content.replace(match, `<script type="module">\n${js}</script>`); 421 376 } 377 + 378 + //////////////////////////////////////////// 379 + // COMPRESSION 380 + //////////////////////////////////////////// 381 + 382 + site.use(brotli()); 383 + site.use(sourceMaps());