From 2f199e048ac99503815dcbe02d10410892b6d812 Mon Sep 17 00:00:00 2001 From: scosman Date: Wed, 31 Jul 2024 09:27:05 -0400 Subject: [PATCH] Add json extension for a valid content-type, which also tells Cloudflare to gzip the content: https://developers.cloudflare.com/speed/optimization/content/brotli/content-compression/ Also: give more relevance to title and description over body --- src/lib/build_index.ts | 2 +- src/routes/(marketing)/search/+page.svelte | 8 ++++++-- .../(marketing)/search/{api => api.json}/+server.ts | 0 3 files changed, 7 insertions(+), 3 deletions(-) rename src/routes/(marketing)/search/{api => api.json}/+server.ts (100%) diff --git a/src/lib/build_index.ts b/src/lib/build_index.ts index cbd45f12..6e7642ae 100644 --- a/src/lib/build_index.ts +++ b/src/lib/build_index.ts @@ -70,7 +70,7 @@ export async function buildAndCacheSearchIndex() { } fs.writeFileSync( - path.resolve("./.svelte-kit/output/client/search/api"), + path.resolve("./.svelte-kit/output/client/search/api.json"), JSON.stringify(data), ) console.log("Search index built") diff --git a/src/routes/(marketing)/search/+page.svelte b/src/routes/(marketing)/search/+page.svelte index ae6a85de..775b98e0 100644 --- a/src/routes/(marketing)/search/+page.svelte +++ b/src/routes/(marketing)/search/+page.svelte @@ -7,7 +7,11 @@ import { dev } from "$app/environment" const fuseOptions = { - keys: ["title", "description", "body"], + keys: [ + { name: "title", weight: 3 }, + { name: "description", weight: 2 }, + { name: "body", weight: 1 }, + ], ignoreLocation: true, threshold: 0.3, } @@ -18,7 +22,7 @@ let error = false onMount(async () => { try { - const response = await fetch("/search/api") + const response = await fetch("/search/api.json") if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`) } diff --git a/src/routes/(marketing)/search/api/+server.ts b/src/routes/(marketing)/search/api.json/+server.ts similarity index 100% rename from src/routes/(marketing)/search/api/+server.ts rename to src/routes/(marketing)/search/api.json/+server.ts