Skip to content

Commit

Permalink
fix collation on types which bloated pf index
Browse files Browse the repository at this point in the history
  • Loading branch information
wkelly17 committed Feb 6, 2025
1 parent e3251d7 commit 81e8f53
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
18 changes: 13 additions & 5 deletions src/components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,24 @@ export function Search(props: SearchProps) {

onMount(async () => {
// eagerly fetch this
// @ts-ignore
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
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) => {
Expand Down Expand Up @@ -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: <not sure on pagefind type>
Expand Down
5 changes: 1 addition & 4 deletions src/data/pubDataApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -571,5 +568,5 @@ function doCollateContent({
isGateway: boolean | undefined;
ietf: string;
}) {
return isGateway || isKnownGatewayContentFormatException(ietf);
return !isGateway || isKnownGatewayContentFormatException(ietf);
}
1 change: 1 addition & 0 deletions src/lib/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions src/sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {CacheFirst, StaleWhileRevalidate} from "workbox-strategies";
import {constants} from "./lib/constants";
import {
bielExternalCacheName,
bielPagefindCacheName,
bielStaticCacheName,
fetchExternalUsfmAndCache,
} from "./lib/web";
Expand Down Expand Up @@ -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],
}),
],
})
);

0 comments on commit 81e8f53

Please sign in to comment.