From 81e8f53ee825ef7ecb783d83e8f436d9165a8456 Mon Sep 17 00:00:00 2001 From: Will Kelly <67284402+wkelly17@users.noreply.github.com> Date: Thu, 6 Feb 2025 12:02:51 -0600 Subject: [PATCH] fix collation on types which bloated pf index --- src/components/Search.tsx | 18 +++++++++++++----- src/data/pubDataApi.ts | 5 +---- src/lib/web.ts | 1 + src/sw.ts | 26 ++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/components/Search.tsx b/src/components/Search.tsx index 8c271c9..a18d880 100644 --- a/src/components/Search.tsx +++ b/src/components/Search.tsx @@ -43,16 +43,24 @@ export function Search(props: SearchProps) { onMount(async () => { // eagerly fetch this - // @ts-ignore // biome-ignore lint/suspicious/noExplicitAny: - const pageFind = (await import("../pagefind/pagefind.js")) as any; + let pageFind: any = null; + // console.log + if (import.meta.env.DEV) { + pageFind = await import("../pagefind/pagefind.js"); + } else { + // @ts-ignore + pageFind = await import("/pagefind/pagefind.js"); + } + // const pageFind = (await import(pathToImport)) as any; pageFind.init(); await pageFind.options({ excerptLength: 5, - baseUrl: "/", }); - + ["bible", "mast", "reg"].forEach((term) => { + pageFind.preload(term); + }); window.pagefind = pageFind; document.body.addEventListener("click", (e) => { @@ -169,7 +177,7 @@ export function Search(props: SearchProps) { } // Search the index using the input value console.log("doing search"); - const search = await window.pagefind.debouncedSearch(inputValue, {}, 150); + const search = await window.pagefind.debouncedSearch(inputValue, {}, 100); // Add the new results // biome-ignore lint/suspicious/noExplicitAny: diff --git a/src/data/pubDataApi.ts b/src/data/pubDataApi.ts index 097930f..88baca6 100644 --- a/src/data/pubDataApi.ts +++ b/src/data/pubDataApi.ts @@ -312,9 +312,6 @@ export async function getLangsWithContentNames({ resourceTypeToDisplayName.get(`${lang.ietf_code}-${c.resource_type}`) || c.title || `${lang.national_name} ${c.resource_type}`; - if (lang.ietf_code === "en") { - console.log(c); - } }); }); return json; @@ -571,5 +568,5 @@ function doCollateContent({ isGateway: boolean | undefined; ietf: string; }) { - return isGateway || isKnownGatewayContentFormatException(ietf); + return !isGateway || isKnownGatewayContentFormatException(ietf); } diff --git a/src/lib/web.ts b/src/lib/web.ts index 9785b4b..35bf1bf 100644 --- a/src/lib/web.ts +++ b/src/lib/web.ts @@ -2,6 +2,7 @@ import type {TsDirectoryFile} from "@customTypes/types"; export const bielExternalCacheName = "biel-external"; export const bielStaticCacheName = "biel-static"; +export const bielPagefindCacheName = "biel-pagefind"; export function isAbsoluteUrl(str: string) { const isAbsoluteRegex = /^(?:[a-z+]+:)?\/\//i; diff --git a/src/sw.ts b/src/sw.ts index 979fab9..f4ad8f9 100644 --- a/src/sw.ts +++ b/src/sw.ts @@ -10,6 +10,7 @@ import {CacheFirst, StaleWhileRevalidate} from "workbox-strategies"; import {constants} from "./lib/constants"; import { bielExternalCacheName, + bielPagefindCacheName, bielStaticCacheName, fetchExternalUsfmAndCache, } from "./lib/web"; @@ -154,3 +155,28 @@ registerRoute( }), "POST" ); + +// pf_meta, pf_index, pf_fragment: +registerRoute( + ({sameOrigin, request}) => { + // https://developer.mozilla.org/en-US/docs/Web/API/Request/destination#font + // todo: debug if this is caching images or not. It seems like it's not caching the webps for some reason + const isPageFind = ["pf_meta", "pf_index", "pf_fragment"].some((item) => + request.url.includes(item) + ); + return isPageFind && sameOrigin; + }, + // Hashes should guarantee strong caching that doesn't need expiring, so go cache first on those, but route through CF as well + new CacheFirst({ + cacheName: bielPagefindCacheName, + plugins: [ + new ExpirationPlugin({ + maxEntries: 2000, + purgeOnQuotaError: true, + }), + new CacheableResponsePlugin({ + statuses: [0, 200, 304], + }), + ], + }) +);